cec-config-gui: make overriding the physical address optional
authorLars Op den Kamp <lars@opdenkamp.eu>
Sun, 19 Feb 2012 00:59:30 +0000 (01:59 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 19 Feb 2012 00:59:30 +0000 (01:59 +0100)
src/cec-config-gui/CecConfigGUI.Designer.cs
src/cec-config-gui/CecConfigGUI.cs

index a48c772dd4ce368bc7e6b968eaa433cbee29c6b6..d45e6d315b32c14e1bca227f86bd82a1403fccee 100644 (file)
       this.cbActivateSource = new System.Windows.Forms.CheckBox();
       this.cbUseTVMenuLanguage = new System.Windows.Forms.CheckBox();
       this.lPlayerConfig = new System.Windows.Forms.Label();
+      this.lAdapterConfig = new System.Windows.Forms.Label();
       this.cbDeviceType = new System.Windows.Forms.ComboBox();
       this.bClose = new System.Windows.Forms.Button();
       this.bSaveConfig = new System.Windows.Forms.Button();
       this.cbPortNumber = new System.Windows.Forms.ComboBox();
+      this.lConnectedPhysicalAddress = new System.Windows.Forms.Label();
       this.tbPhysicalAddress = new System.Windows.Forms.TextBox();
       this.cbConnectedDevice = new System.Windows.Forms.ComboBox();
       this.lDeviceType = new System.Windows.Forms.Label();
-      this.lPhysicalAddress = new System.Windows.Forms.Label();
       this.lConnectedDevice = new System.Windows.Forms.Label();
       this.lPortNumber = new System.Windows.Forms.Label();
       this.tbButtons = new System.Windows.Forms.TabPage();
       this.label1 = new System.Windows.Forms.Label();
       this.dgButtons = new System.Windows.Forms.DataGridView();
       this.CecButtonName = new System.Windows.Forms.DataGridViewTextBoxColumn();
-      this.playerButtonDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
       this.cecButtonConfigBindingSource = new System.Windows.Forms.BindingSource(this.components);
       this.tbTestCommands = new System.Windows.Forms.TabPage();
       this.bRescanDevices = new System.Windows.Forms.Button();
@@ -73,8 +73,7 @@
       this.helpConnectedHDMIDevice = new System.Windows.Forms.ToolTip(this.components);
       this.helpPhysicalAddress = new System.Windows.Forms.ToolTip(this.components);
       this.helpDeviceType = new System.Windows.Forms.ToolTip(this.components);
-      this.lConnectedPhysicalAddress = new System.Windows.Forms.Label();
-      this.lAdapterConfig = new System.Windows.Forms.Label();
+      this.cbOverrideAddress = new System.Windows.Forms.CheckBox();
       this.tabControl1.SuspendLayout();
       this.Configuration.SuspendLayout();
       this.tbButtons.SuspendLayout();
@@ -99,6 +98,7 @@
       // 
       // Configuration
       // 
+      this.Configuration.Controls.Add(this.cbOverrideAddress);
       this.Configuration.Controls.Add(this.bReloadConfig);
       this.Configuration.Controls.Add(this.cbVendorOverride);
       this.Configuration.Controls.Add(this.cbVendorId);
       this.Configuration.Controls.Add(this.tbPhysicalAddress);
       this.Configuration.Controls.Add(this.cbConnectedDevice);
       this.Configuration.Controls.Add(this.lDeviceType);
-      this.Configuration.Controls.Add(this.lPhysicalAddress);
       this.Configuration.Controls.Add(this.lConnectedDevice);
       this.Configuration.Controls.Add(this.lPortNumber);
       this.Configuration.Location = new System.Drawing.Point(4, 22);
       this.lPlayerConfig.TabIndex = 16;
       this.lPlayerConfig.Text = "Player Configuration";
       // 
+      // lAdapterConfig
+      // 
+      this.lAdapterConfig.AutoSize = true;
+      this.lAdapterConfig.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+      this.lAdapterConfig.Location = new System.Drawing.Point(6, 3);
+      this.lAdapterConfig.Name = "lAdapterConfig";
+      this.lAdapterConfig.Size = new System.Drawing.Size(213, 24);
+      this.lAdapterConfig.TabIndex = 15;
+      this.lAdapterConfig.Text = "Adapter Configuration";
+      // 
       // cbDeviceType
       // 
       this.cbDeviceType.Enabled = false;
       this.helpPortNumber.SetToolTip(this.cbPortNumber, "The HDMI port number, to which you connected your USB-CEC adapter.");
       this.cbPortNumber.SelectedIndexChanged += new System.EventHandler(this.connectedDevice_SelectedIndexChanged);
       // 
+      // lConnectedPhysicalAddress
+      // 
+      this.lConnectedPhysicalAddress.AutoSize = true;
+      this.lConnectedPhysicalAddress.Location = new System.Drawing.Point(340, 71);
+      this.lConnectedPhysicalAddress.Name = "lConnectedPhysicalAddress";
+      this.lConnectedPhysicalAddress.Size = new System.Drawing.Size(75, 13);
+      this.lConnectedPhysicalAddress.TabIndex = 10;
+      this.lConnectedPhysicalAddress.Text = "Address: 0000";
+      // 
       // tbPhysicalAddress
       // 
       this.tbPhysicalAddress.Enabled = false;
       this.lDeviceType.TabIndex = 3;
       this.lDeviceType.Text = "Device type";
       // 
-      // lPhysicalAddress
-      // 
-      this.lPhysicalAddress.AutoSize = true;
-      this.lPhysicalAddress.Location = new System.Drawing.Point(6, 98);
-      this.lPhysicalAddress.Name = "lPhysicalAddress";
-      this.lPhysicalAddress.Size = new System.Drawing.Size(86, 13);
-      this.lPhysicalAddress.TabIndex = 2;
-      this.lPhysicalAddress.Text = "Physical address";
-      // 
       // lConnectedDevice
       // 
       this.lConnectedDevice.AutoSize = true;
       this.dgButtons.AutoGenerateColumns = false;
       this.dgButtons.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
       this.dgButtons.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
-            this.CecButtonName,
-            this.playerButtonDataGridViewTextBoxColumn});
+            this.CecButtonName});
       this.dgButtons.DataSource = this.cecButtonConfigBindingSource;
       this.dgButtons.Location = new System.Drawing.Point(7, 7);
       this.dgButtons.Name = "dgButtons";
       this.CecButtonName.ReadOnly = true;
       this.CecButtonName.Width = 260;
       // 
-      // playerButtonDataGridViewTextBoxColumn
-      // 
-      this.playerButtonDataGridViewTextBoxColumn.DataPropertyName = "PlayerButton";
-      this.playerButtonDataGridViewTextBoxColumn.FillWeight = 260F;
-      this.playerButtonDataGridViewTextBoxColumn.HeaderText = "Mapped to";
-      this.playerButtonDataGridViewTextBoxColumn.Name = "playerButtonDataGridViewTextBoxColumn";
-      this.playerButtonDataGridViewTextBoxColumn.Width = 260;
-      // 
       // cecButtonConfigBindingSource
       // 
       this.cecButtonConfigBindingSource.DataSource = typeof(CecConfigGui.CecButtonConfig);
       this.lStatus.TabIndex = 2;
       this.lStatus.Text = "Initialising...";
       // 
-      // lConnectedPhysicalAddress
-      // 
-      this.lConnectedPhysicalAddress.AutoSize = true;
-      this.lConnectedPhysicalAddress.Location = new System.Drawing.Point(340, 71);
-      this.lConnectedPhysicalAddress.Name = "lConnectedPhysicalAddress";
-      this.lConnectedPhysicalAddress.Size = new System.Drawing.Size(75, 13);
-      this.lConnectedPhysicalAddress.TabIndex = 10;
-      this.lConnectedPhysicalAddress.Text = "Address: 0000";
-      // 
-      // lAdapterConfig
+      // cbOverrideAddress
       // 
-      this.lAdapterConfig.AutoSize = true;
-      this.lAdapterConfig.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
-      this.lAdapterConfig.Location = new System.Drawing.Point(6, 3);
-      this.lAdapterConfig.Name = "lAdapterConfig";
-      this.lAdapterConfig.Size = new System.Drawing.Size(213, 24);
-      this.lAdapterConfig.TabIndex = 15;
-      this.lAdapterConfig.Text = "Adapter Configuration";
+      this.cbOverrideAddress.AutoSize = true;
+      this.cbOverrideAddress.Enabled = false;
+      this.cbOverrideAddress.Location = new System.Drawing.Point(10, 97);
+      this.cbOverrideAddress.Name = "cbOverrideAddress";
+      this.cbOverrideAddress.Size = new System.Drawing.Size(147, 17);
+      this.cbOverrideAddress.TabIndex = 31;
+      this.cbOverrideAddress.Text = "Override physical address";
+      this.cbOverrideAddress.UseVisualStyleBackColor = true;
+      this.cbOverrideAddress.CheckedChanged += new System.EventHandler(this.cbOverrideAddress_CheckedChanged);
       // 
       // CecConfigGUI
       // 
     private System.Windows.Forms.TabPage LogOutput;
     private System.Windows.Forms.Label lPortNumber;
     private System.Windows.Forms.Label lDeviceType;
-    private System.Windows.Forms.Label lPhysicalAddress;
     private System.Windows.Forms.Label lConnectedDevice;
     private System.Windows.Forms.ComboBox cbConnectedDevice;
     private System.Windows.Forms.TextBox tbPhysicalAddress;
     private System.Windows.Forms.Button bRescanDevices;
     private System.Windows.Forms.Label lConnectedPhysicalAddress;
     private System.Windows.Forms.Label lAdapterConfig;
+    private System.Windows.Forms.CheckBox cbOverrideAddress;
   }
 }
\ No newline at end of file
index 06e66018ff2feee19c3a48f89dde97376ebc7b52..5004e041024dfa77eac9913bfbc49a6fd09b4482 100644 (file)
@@ -326,7 +326,8 @@ namespace CecConfigGui
     {
       SetControlEnabled(cbPortNumber, val && !Config.AutodetectAddress);
       SetControlEnabled(cbConnectedDevice, cbConnectedDevice.Items.Count > 1 && !Config.AutodetectAddress ? val : false);
-      SetControlEnabled(tbPhysicalAddress, val && !Config.AutodetectAddress);
+      SetControlEnabled(cbOverrideAddress, val);
+      SetControlEnabled(tbPhysicalAddress, val && !Config.AutodetectAddress && cbOverrideAddress.Checked);
       SetControlEnabled(cbDeviceType, val);
       SetControlEnabled(cbUseTVMenuLanguage, val);
       SetControlEnabled(cbActivateSource, val);
@@ -413,7 +414,7 @@ namespace CecConfigGui
 
     public void SetPhysicalAddress(ushort physicalAddress)
     {
-      if (!SuppressUpdates && ActiveProcess == null)
+      if (!SuppressUpdates && ActiveProcess == null && cbOverrideAddress.Checked)
       {
         SetControlsEnabled(false);
         SetControlText(cbPortNumber, string.Empty);
@@ -481,9 +482,15 @@ namespace CecConfigGui
     #endregion
 
     #region Configuration tab
+    private void cbOverrideAddress_CheckedChanged(object sender, EventArgs e)
+    {
+      SetControlEnabled(tbPhysicalAddress, ((CheckBox)sender).Checked);
+    }
+
     private void tbPhysicalAddress_TextChanged(object sender, EventArgs e)
     {
-      if (tbPhysicalAddress.Text.Length != 4)
+      if (tbPhysicalAddress.Text.Length != 4 ||
+          cbOverrideAddress.Checked)
         return;
       ushort physicalAddress = 0;
       if (!ushort.TryParse(tbPhysicalAddress.Text, NumberStyles.AllowHexSpecifier, null, out physicalAddress))
@@ -583,20 +590,24 @@ namespace CecConfigGui
               // only supported by 1.5.0+ clients
               output.AppendLine("<!-- the following lines are only supported by v1.5.0+ clients -->");
               output.AppendLine("<setting id=\"activate_source\" value=\"" + (Config.ActivateSource ? 1 : 0) + "\" />");
-              output.AppendLine("<setting id=\"physical_address\" value=\"" + string.Format("{0,4:X}", Config.PhysicalAddress) + "\" />");
+              output.AppendLine("<setting id=\"physical_address\" value=\"" + string.Format("{0,4:X}", cbOverrideAddress.Checked ? Config.PhysicalAddress : 0).Trim() + "\" />");
               output.AppendLine("<setting id=\"device_type\" value=\"" + (int)Config.DeviceTypes.Types[0] + "\" />");
               output.AppendLine("<setting id=\"tv_vendor\" value=\"" + string.Format("{0,6:X}", (int)Config.TvVendor).Trim() + "\" />");
 
               output.Append("<setting id=\"wake_devices\" value=\"");
+              StringBuilder strWakeDevices = new StringBuilder();
               foreach (CecLogicalAddress addr in Config.WakeDevices.Addresses)
                 if (addr != CecLogicalAddress.Unknown)
-                  output.Append(" " + (int)addr);
+                  strWakeDevices.Append(" " + (int)addr);
+              output.Append(strWakeDevices.ToString().Trim());
               output.AppendLine("\" />");
 
               output.Append("<setting id=\"standby_devices\" value=\"");
+              StringBuilder strSleepDevices = new StringBuilder();
               foreach (CecLogicalAddress addr in Config.PowerOffDevices.Addresses)
                 if (addr != CecLogicalAddress.Unknown)
-                  output.Append(" " + (int)addr);
+                  strSleepDevices.Append(" " + (int)addr);
+              output.Append(strSleepDevices.ToString().Trim()); 
               output.AppendLine("\" />");
 
               output.AppendLine("</settings>");