From: Lars Op den Kamp Date: Wed, 15 Feb 2012 15:02:26 +0000 (+0100) Subject: cec-config-gui: added the new parameters. cleanup round. X-Git-Tag: upstream/2.2.0~1^2~35^2~44 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=75af24f133bfd316bc69a9b63e190047186f169a;p=deb_libcec.git cec-config-gui: added the new parameters. cleanup round. --- diff --git a/src/cec-config-gui/AsyncForm.cs b/src/cec-config-gui/AsyncForm.cs new file mode 100644 index 0000000..4584d75 --- /dev/null +++ b/src/cec-config-gui/AsyncForm.cs @@ -0,0 +1,118 @@ +using System; +using System.Windows.Forms; + +namespace CecConfigGui +{ + public class AsyncForm : Form + { + delegate void SetControlEnabledCallback(Control control, bool val); + public void SetControlEnabled(Control control, bool val) + { + if (control.InvokeRequired) + { + SetControlEnabledCallback d = new SetControlEnabledCallback(SetControlEnabled); + try + { + this.Invoke(d, new object[] { control, val }); + } + catch (Exception) { } + } + else + { + control.Enabled = val; + } + } + + delegate void SetControlTextCallback(Control control, string val); + public void SetControlText(Control control, string val) + { + if (control.InvokeRequired) + { + SetControlTextCallback d = new SetControlTextCallback(SetControlText); + try + { + this.Invoke(d, new object[] { control, val }); + } + catch (Exception) { } + } + else + { + control.Text = val; + } + } + + delegate void SetCheckboxCheckedCallback(CheckBox control, bool val); + public void SetCheckboxChecked(CheckBox control, bool val) + { + if (control.InvokeRequired) + { + SetCheckboxCheckedCallback d = new SetCheckboxCheckedCallback(SetCheckboxChecked); + try + { + this.Invoke(d, new object[] { control, val }); + } + catch (Exception) { } + } + else + { + control.Checked = val; + } + } + + delegate void SetProgressValueCallback(ProgressBar control, int val); + public void SetProgressValue(ProgressBar control, int val) + { + if (control.InvokeRequired) + { + SetProgressValueCallback d = new SetProgressValueCallback(SetProgressValue); + try + { + this.Invoke(d, new object[] { control, val }); + } + catch (Exception) { } + } + else + { + control.Value = val; + } + } + + delegate void SetComboBoxItemsCallback(ComboBox control, string selectedText, object[] val); + public void SetComboBoxItems(ComboBox control, string selectedText, object[] val) + { + if (control.InvokeRequired) + { + SetComboBoxItemsCallback d = new SetComboBoxItemsCallback(SetComboBoxItems); + try + { + this.Invoke(d, new object[] { control, selectedText, val }); + } + catch (Exception) { } + } + else + { + control.Items.Clear(); + control.Items.AddRange(val); + control.Text = selectedText; + } + } + + delegate void SetControlVisibleCallback(Control control, bool val); + public void SetControlVisible(Control control, bool val) + { + if (control.InvokeRequired) + { + SetControlVisibleCallback d = new SetControlVisibleCallback(SetControlVisible); + try + { + this.Invoke(d, new object[] { control, val }); + } + catch (Exception) { } + } + else + { + control.Visible = val; + } + } + } +} diff --git a/src/cec-config-gui/CecConfigGUI.Designer.cs b/src/cec-config-gui/CecConfigGUI.Designer.cs index 7225d42..c3d45e1 100644 --- a/src/cec-config-gui/CecConfigGUI.Designer.cs +++ b/src/cec-config-gui/CecConfigGUI.Designer.cs @@ -31,10 +31,13 @@ this.components = new System.ComponentModel.Container(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.Configuration = new System.Windows.Forms.TabPage(); + this.lPowerOff = new System.Windows.Forms.Label(); + this.cbPowerOffDevices = new System.Windows.Forms.CheckedListBox(); + this.lWakeDevices = new System.Windows.Forms.Label(); + this.cbWakeDevices = new System.Windows.Forms.CheckedListBox(); this.cbPowerOffOnStandby = new System.Windows.Forms.CheckBox(); this.cbPowerOffScreensaver = new System.Windows.Forms.CheckBox(); - this.cbPowerOffShutdown = new System.Windows.Forms.CheckBox(); - this.cbPowerOnStartup = new System.Windows.Forms.CheckBox(); + 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(); @@ -50,8 +53,11 @@ 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.bMute = new System.Windows.Forms.Button(); this.bVolDown = new System.Windows.Forms.Button(); @@ -77,18 +83,15 @@ 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.label1 = new System.Windows.Forms.Label(); - this.cbWakeDevices = new System.Windows.Forms.CheckedListBox(); - this.lWakeDevices = new System.Windows.Forms.Label(); - this.playerButtonDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.cecButtonConfigBindingSource = new System.Windows.Forms.BindingSource(this.components); + this.cbVendorId = new System.Windows.Forms.ComboBox(); + this.cbVendorOverride = new System.Windows.Forms.CheckBox(); this.tabControl1.SuspendLayout(); this.Configuration.SuspendLayout(); this.tbButtons.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dgButtons)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.cecButtonConfigBindingSource)).BeginInit(); this.tbTestCommands.SuspendLayout(); this.LogOutput.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.cecButtonConfigBindingSource)).BeginInit(); this.SuspendLayout(); // // tabControl1 @@ -105,12 +108,15 @@ // // Configuration // + this.Configuration.Controls.Add(this.cbVendorOverride); + this.Configuration.Controls.Add(this.cbVendorId); + this.Configuration.Controls.Add(this.lPowerOff); + this.Configuration.Controls.Add(this.cbPowerOffDevices); this.Configuration.Controls.Add(this.lWakeDevices); this.Configuration.Controls.Add(this.cbWakeDevices); this.Configuration.Controls.Add(this.cbPowerOffOnStandby); this.Configuration.Controls.Add(this.cbPowerOffScreensaver); - this.Configuration.Controls.Add(this.cbPowerOffShutdown); - this.Configuration.Controls.Add(this.cbPowerOnStartup); + this.Configuration.Controls.Add(this.cbActivateSource); this.Configuration.Controls.Add(this.cbUseTVMenuLanguage); this.Configuration.Controls.Add(this.lPlayerConfig); this.Configuration.Controls.Add(this.lAdapterConfig); @@ -133,6 +139,74 @@ this.Configuration.Text = "Configuration"; this.Configuration.UseVisualStyleBackColor = true; // + // lPowerOff + // + this.lPowerOff.AutoSize = true; + this.lPowerOff.Location = new System.Drawing.Point(465, 203); + this.lPowerOff.Name = "lPowerOff"; + this.lPowerOff.Size = new System.Drawing.Size(124, 13); + this.lPowerOff.TabIndex = 26; + this.lPowerOff.Text = "Power off when stopping"; + // + // cbPowerOffDevices + // + this.cbPowerOffDevices.FormattingEnabled = true; + this.cbPowerOffDevices.Items.AddRange(new object[] { + "0: TV", + "1: Recorder 1", + "2: Recorder 2", + "3: Tuner 1", + "4: Playback 1", + "5: Audio system", + "6: Tuner 2", + "7: Tuner 3", + "8: Playback 2", + "9: Recorder 3", + "A: Tuner 4", + "B: Playback 3", + "C: Reserved 1", + "D: Reserved 2", + "E: Free use", + "F: Broadcast"}); + this.cbPowerOffDevices.Location = new System.Drawing.Point(467, 220); + this.cbPowerOffDevices.Name = "cbPowerOffDevices"; + this.cbPowerOffDevices.Size = new System.Drawing.Size(118, 94); + this.cbPowerOffDevices.TabIndex = 25; + // + // lWakeDevices + // + this.lWakeDevices.AutoSize = true; + this.lWakeDevices.Location = new System.Drawing.Point(345, 203); + this.lWakeDevices.Name = "lWakeDevices"; + this.lWakeDevices.Size = new System.Drawing.Size(102, 13); + this.lWakeDevices.TabIndex = 24; + this.lWakeDevices.Text = "Wake when starting"; + // + // cbWakeDevices + // + this.cbWakeDevices.FormattingEnabled = true; + this.cbWakeDevices.Items.AddRange(new object[] { + "0: TV", + "1: Recorder 1", + "2: Recorder 2", + "3: Tuner 1", + "4: Playback 1", + "5: Audio system", + "6: Tuner 2", + "7: Tuner 3", + "8: Playback 2", + "9: Recorder 3", + "A: Tuner 4", + "B: Playback 3", + "C: Reserved 1", + "D: Reserved 2", + "E: Free use", + "F: Broadcast"}); + this.cbWakeDevices.Location = new System.Drawing.Point(337, 220); + this.cbWakeDevices.Name = "cbWakeDevices"; + this.cbWakeDevices.Size = new System.Drawing.Size(118, 94); + this.cbWakeDevices.TabIndex = 23; + // // cbPowerOffOnStandby // this.cbPowerOffOnStandby.AutoSize = true; @@ -155,33 +229,22 @@ this.cbPowerOffScreensaver.Text = "Put devices in standby mode when activating screensaver"; this.cbPowerOffScreensaver.UseVisualStyleBackColor = true; // - // cbPowerOffShutdown + // cbActivateSource // - this.cbPowerOffShutdown.AutoSize = true; - this.cbPowerOffShutdown.Enabled = false; - this.cbPowerOffShutdown.Location = new System.Drawing.Point(10, 249); - this.cbPowerOffShutdown.Name = "cbPowerOffShutdown"; - this.cbPowerOffShutdown.Size = new System.Drawing.Size(317, 17); - this.cbPowerOffShutdown.TabIndex = 20; - this.cbPowerOffShutdown.Text = "Power off devices when stopping the media player application"; - this.cbPowerOffShutdown.UseVisualStyleBackColor = true; - // - // cbPowerOnStartup - // - this.cbPowerOnStartup.AutoSize = true; - this.cbPowerOnStartup.Enabled = false; - this.cbPowerOnStartup.Location = new System.Drawing.Point(10, 225); - this.cbPowerOnStartup.Name = "cbPowerOnStartup"; - this.cbPowerOnStartup.Size = new System.Drawing.Size(306, 17); - this.cbPowerOnStartup.TabIndex = 19; - this.cbPowerOnStartup.Text = "Power on the TV when starting the media player application"; - this.cbPowerOnStartup.UseVisualStyleBackColor = true; + this.cbActivateSource.AutoSize = true; + this.cbActivateSource.Enabled = false; + this.cbActivateSource.Location = new System.Drawing.Point(10, 249); + this.cbActivateSource.Name = "cbActivateSource"; + this.cbActivateSource.Size = new System.Drawing.Size(284, 17); + this.cbActivateSource.TabIndex = 19; + this.cbActivateSource.Text = "Make the media player the active source when starting"; + this.cbActivateSource.UseVisualStyleBackColor = true; // // cbUseTVMenuLanguage // this.cbUseTVMenuLanguage.AutoSize = true; this.cbUseTVMenuLanguage.Enabled = false; - this.cbUseTVMenuLanguage.Location = new System.Drawing.Point(10, 201); + this.cbUseTVMenuLanguage.Location = new System.Drawing.Point(10, 225); this.cbUseTVMenuLanguage.Name = "cbUseTVMenuLanguage"; this.cbUseTVMenuLanguage.Size = new System.Drawing.Size(168, 17); this.cbUseTVMenuLanguage.TabIndex = 18; @@ -192,7 +255,7 @@ // this.lPlayerConfig.AutoSize = true; this.lPlayerConfig.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lPlayerConfig.Location = new System.Drawing.Point(6, 165); + this.lPlayerConfig.Location = new System.Drawing.Point(6, 188); this.lPlayerConfig.Name = "lPlayerConfig"; this.lPlayerConfig.Size = new System.Drawing.Size(198, 24); this.lPlayerConfig.TabIndex = 16; @@ -345,6 +408,17 @@ this.tbButtons.Text = "Button Configuration"; this.tbButtons.UseVisualStyleBackColor = true; // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0))))); + this.label1.Location = new System.Drawing.Point(118, 252); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(354, 31); + this.label1.TabIndex = 1; + this.label1.Text = "NOT IMPLEMENTED YET"; + // // dgButtons // this.dgButtons.AllowUserToAddRows = false; @@ -373,6 +447,18 @@ 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); + // // tbTestCommands // this.tbTestCommands.Controls.Add(this.bMute); @@ -621,62 +707,36 @@ this.lStatus.TabIndex = 2; this.lStatus.Text = "Initialising..."; // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0))))); - this.label1.Location = new System.Drawing.Point(118, 252); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(354, 31); - this.label1.TabIndex = 1; - this.label1.Text = "NOT IMPLEMENTED YET"; - // - // cbWakeDevices - // - this.cbWakeDevices.FormattingEnabled = true; - this.cbWakeDevices.Items.AddRange(new object[] { - "0: TV", - "1: Recorder 1", - "2: Recorder 2", - "3: Tuner 1", - "4: Playback 1", - "5: Audio system", - "6: Tuner 2", - "7: Tuner 3", - "8: Playback 2", - "9: Recorder 3", - "A: Tuner 4", - "B: Playback 3", - "C: Reserved 1", - "D: Reserved 2", - "E: Free use", - "F: Broadcast"}); - this.cbWakeDevices.Location = new System.Drawing.Point(333, 218); - this.cbWakeDevices.Name = "cbWakeDevices"; - this.cbWakeDevices.Size = new System.Drawing.Size(118, 94); - this.cbWakeDevices.TabIndex = 23; - // - // lWakeDevices - // - this.lWakeDevices.AutoSize = true; - this.lWakeDevices.Location = new System.Drawing.Point(339, 201); - this.lWakeDevices.Name = "lWakeDevices"; - this.lWakeDevices.Size = new System.Drawing.Size(102, 13); - this.lWakeDevices.TabIndex = 24; - this.lWakeDevices.Text = "Wake when starting"; - // - // 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); + // cbVendorId + // + this.cbVendorId.Enabled = false; + this.cbVendorId.FormattingEnabled = true; + this.cbVendorId.Items.AddRange(new object[] { + "- autodetect -", + "LG", + "Onkyo", + "Panasonic", + "Philips", + "Pioneer", + "Samsung", + "Sony", + "Yamaha"}); + this.cbVendorId.Location = new System.Drawing.Point(174, 153); + this.cbVendorId.Name = "cbVendorId"; + this.cbVendorId.Size = new System.Drawing.Size(121, 21); + this.cbVendorId.TabIndex = 28; + this.cbVendorId.Text = "- autodetect -"; + this.helpDeviceType.SetToolTip(this.cbVendorId, "Only set this value when autodetection isn\'t working"); + // + // cbVendorOverride + // + this.cbVendorOverride.AutoSize = true; + this.cbVendorOverride.Location = new System.Drawing.Point(10, 156); + this.cbVendorOverride.Name = "cbVendorOverride"; + this.cbVendorOverride.Size = new System.Drawing.Size(130, 17); + this.cbVendorOverride.TabIndex = 29; + this.cbVendorOverride.Text = "Override TV vendor id"; + this.cbVendorOverride.UseVisualStyleBackColor = true; // // CecConfigGUI // @@ -694,11 +754,11 @@ this.tbButtons.ResumeLayout(false); this.tbButtons.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dgButtons)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.cecButtonConfigBindingSource)).EndInit(); this.tbTestCommands.ResumeLayout(false); this.tbTestCommands.PerformLayout(); this.LogOutput.ResumeLayout(false); this.LogOutput.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.cecButtonConfigBindingSource)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -726,8 +786,7 @@ private System.Windows.Forms.Label lAdapterConfig; private System.Windows.Forms.CheckBox cbPowerOffOnStandby; private System.Windows.Forms.CheckBox cbPowerOffScreensaver; - private System.Windows.Forms.CheckBox cbPowerOffShutdown; - private System.Windows.Forms.CheckBox cbPowerOnStartup; + private System.Windows.Forms.CheckBox cbActivateSource; private System.Windows.Forms.CheckBox cbUseTVMenuLanguage; private System.Windows.Forms.Label lPlayerConfig; private System.Windows.Forms.ToolTip helpPortNumber; @@ -759,5 +818,9 @@ private System.Windows.Forms.Label label1; private System.Windows.Forms.Label lWakeDevices; private System.Windows.Forms.CheckedListBox cbWakeDevices; + private System.Windows.Forms.Label lPowerOff; + private System.Windows.Forms.CheckedListBox cbPowerOffDevices; + private System.Windows.Forms.CheckBox cbVendorOverride; + private System.Windows.Forms.ComboBox cbVendorId; } } \ No newline at end of file diff --git a/src/cec-config-gui/CecConfigGUI.cs b/src/cec-config-gui/CecConfigGUI.cs index e41c292..b1731cf 100644 --- a/src/cec-config-gui/CecConfigGUI.cs +++ b/src/cec-config-gui/CecConfigGUI.cs @@ -14,7 +14,7 @@ using System.Xml; namespace CecConfigGui { - public partial class CecConfigGUI : Form + public partial class CecConfigGUI : AsyncForm { public CecConfigGUI() { @@ -91,6 +91,27 @@ namespace CecConfigGui config.BaseDevice = (CecLogicalAddress)iDevice; } break; + case "cec_power_on_startup": + if (value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes")) + { + config.ActivateSource = true; + config.WakeDevices.Set(CecLogicalAddress.Tv); + } + break; + case "cec_power_off_shutdown": + if (value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes")) + config.PowerOffDevices.Set(CecLogicalAddress.Broadcast); + break; + case "cec_standby_screensaver": + config.PowerOffScreensaver = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes"); + break; + case "standby_pc_on_tv_standby": + config.PowerOffOnStandby = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes"); + break; + case "use_tv_menu_language": + config.UseTVMenuLanguage = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes"); + break; + // 1.5.0+ settings case "physical_address": { ushort physicalAddress = 0; @@ -105,20 +126,36 @@ namespace CecConfigGui config.DeviceTypes.Types[0] = (CecDeviceType)iType; } break; - case "cec_power_on_startup": - config.PowerOnStartup = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes"); - break; - case "cec_power_off_shutdown": - config.PowerOffShutdown = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes"); - break; - case "cec_standby_screensaver": - config.PowerOffScreensaver = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes"); + case "tv_vendor": + { + UInt64 iVendor; + if (UInt64.TryParse(value, out iVendor)) + config.TvVendor = (CecVendorId)iVendor; + } break; - case "standby_pc_on_tv_standby": - config.PowerOffOnStandby = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes"); + case "wake_devices": + { + config.WakeDevices.Clear(); + string[] split = value.Split(new char[] { ' ' }); + foreach (string dev in split) + { + byte iLogicalAddress; + if (byte.TryParse(dev, out iLogicalAddress)) + config.WakeDevices.Set((CecLogicalAddress)iLogicalAddress); + } + } break; - case "use_tv_menu_language": - config.UseTVMenuLanguage = value.Equals("1") || value.ToLower().Equals("true") || value.ToLower().Equals("yes"); + case "standby_devices": + { + config.PowerOffDevices.Clear(); + string[] split = value.Split(new char[] { ' ' }); + foreach (string dev in split) + { + byte iLogicalAddress; + if (byte.TryParse(dev, out iLogicalAddress)) + config.PowerOffDevices.Set((CecLogicalAddress)iLogicalAddress); + } + } break; case "enabled": break; @@ -222,130 +259,113 @@ namespace CecConfigGui this.cecButtonConfigBindingSource.Add(new CecButtonConfigItem("(Samsung) Return", (new CecSharp.CecKeypress() { Keycode = 0x91 }), string.Empty)); } - public int ConfigurationChanged(LibCECConfiguration config) - { - SetControlText(this.tbPhysicalAddress, String.Format("{0,4:X}", config.PhysicalAddress)); - return 1; - } - - public int ReceiveCommand(CecCommand command) - { - return 1; - } - - public int ReceiveKeypress(CecKeypress key) - { - SelectKeypressRow(key); - return 1; - } - - delegate void SelectKeypressRowCallback(CecKeypress key); - private void SelectKeypressRow(CecKeypress key) + private void ProcessEventHandler(object src, UpdateEvent updateEvent) { - if (dgButtons.InvokeRequired) - { - SelectKeypressRowCallback d = new SelectKeypressRowCallback(SelectKeypressRow); - try - { - this.Invoke(d, new object[] { key }); - } - catch (Exception) { } - } - else + switch (updateEvent.Type) { - int rowIndex = -1; - foreach (DataGridViewRow row in dgButtons.Rows) - { - CecButtonConfigItem item = row.DataBoundItem as CecButtonConfigItem; - if (item != null && item.Key.Keycode == key.Keycode) - { - rowIndex = row.Index; - row.Selected = true; - item.Enabled = true; - } - else + case UpdateEventType.StatusText: + SetControlText(lStatus, updateEvent.StringValue); + break; + case UpdateEventType.PhysicalAddress: + Config.PhysicalAddress = (ushort)updateEvent.IntValue; + SetControlText(tbPhysicalAddress, string.Format("{0,4:X}", updateEvent.IntValue)); + break; + case UpdateEventType.ProgressBar: + SetProgressValue(pProgress, updateEvent.IntValue); + break; + case UpdateEventType.TVVendorId: + TVVendor = (CecVendorId)updateEvent.IntValue; + UpdateSelectedDevice(); + break; + case UpdateEventType.BaseDevicePhysicalAddress: + SetControlText(lConnectedPhysicalAddress, string.Format("Address: {0,4:X}", updateEvent.IntValue)); + break; + case UpdateEventType.BaseDevice: + Config.BaseDevice = (CecLogicalAddress)updateEvent.IntValue; + break; + case UpdateEventType.HDMIPort: + Config.HDMIPort = (byte)updateEvent.IntValue; + break; + case UpdateEventType.MenuLanguage: + SetControlText(cbUseTVMenuLanguage, "Use the TV's language setting" + (updateEvent.StringValue.Length > 0 ? " (" + updateEvent.StringValue + ")" : "")); + break; + case UpdateEventType.HasAVRDevice: + if (HasAVRDevice != updateEvent.BoolValue) { - row.Selected = false; + HasAVRDevice = updateEvent.BoolValue; + UpdateSelectedDevice(); } - } - if (rowIndex > -1) - dgButtons.FirstDisplayedScrollingRowIndex = rowIndex; + break; + case UpdateEventType.AVRVendorId: + AVRVendor = (CecVendorId)updateEvent.IntValue; + UpdateSelectedDevice(); + break; + case UpdateEventType.Configuration: + SuppressUpdates = true; + ConfigurationChanged(updateEvent.ConfigValue); + SuppressUpdates = false; + break; + case UpdateEventType.ProcessCompleted: + ActiveProcess = null; + SetControlsEnabled(true); + break; } } - delegate void AddLogMessageCallback(CecLogMessage message); - private void AddLogMessage(CecLogMessage message) + public void SetPhysicalAddress(ushort physicalAddress) { - if (tbLog.InvokeRequired) + if (!SuppressUpdates && ActiveProcess == null) { - AddLogMessageCallback d = new AddLogMessageCallback(AddLogMessage); - try - { - this.Invoke(d, new object[] { message }); - } - catch (Exception) { } + SetControlsEnabled(false); + SetControlText(cbPortNumber, string.Empty); + SetControlText(cbConnectedDevice, string.Empty); + ActiveProcess = new UpdatePhysicalAddress(ref Lib, physicalAddress); + ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); + (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); } - else - { - string strLevel = ""; - bool display = false; - switch (message.Level) - { - case CecLogLevel.Error: - strLevel = "ERROR: "; - display = cbLogError.Checked; - break; - case CecLogLevel.Warning: - strLevel = "WARNING: "; - display = cbLogWarning.Checked; - break; - case CecLogLevel.Notice: - strLevel = "NOTICE: "; - display = cbLogNotice.Checked; - break; - case CecLogLevel.Traffic: - strLevel = "TRAFFIC: "; - display = cbLogTraffic.Checked; - break; - case CecLogLevel.Debug: - strLevel = "DEBUG: "; - display = cbLogDebug.Checked; - break; - default: - break; - } + } - if (display) - { - string strLog = string.Format("{0} {1,16} {2}", strLevel, message.Time, message.Message) + System.Environment.NewLine; - tbLog.Text += strLog; - tbLog.Select(tbLog.Text.Length, 0); - tbLog.ScrollToCaret(); - } + public void SendImageViewOn(CecLogicalAddress address) + { + if (!SuppressUpdates && ActiveProcess == null) + { + SetControlsEnabled(false); + ActiveProcess = new SendImageViewOn(ref Lib, address); + ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); + (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); } } - public int ReceiveLogMessage(CecLogMessage message) + public void ActivateSource(CecLogicalAddress address) { - AddLogMessage(message); - return 1; + if (!SuppressUpdates && ActiveProcess == null) + { + SetControlsEnabled(false); + ActiveProcess = new SendActivateSource(ref Lib, address); + ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); + (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); + } } - delegate void SetControlEnabledCallback(Control control, bool val); - private void SetControlEnabled(Control control, bool val) + public void SendStandby(CecLogicalAddress address) { - if (control.InvokeRequired) + if (!SuppressUpdates && ActiveProcess == null) { - SetControlEnabledCallback d = new SetControlEnabledCallback(SetControlEnabled); - try - { - this.Invoke(d, new object[] { control, val }); - } - catch (Exception) { } + SetControlsEnabled(false); + ActiveProcess = new SendStandby(ref Lib, address); + ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); + (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); } - else + } + + public void ShowDeviceInfo(CecLogicalAddress address) + { + if (!SuppressUpdates && ActiveProcess == null) { - control.Enabled = val; + SetControlsEnabled(false); + ActiveProcess = new ShowDeviceInfo(this, ref Lib, address); + ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); + (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); } } @@ -356,11 +376,13 @@ namespace CecConfigGui SetControlEnabled(tbPhysicalAddress, val); SetControlEnabled(cbDeviceType, false); // TODO not implemented yet SetControlEnabled(cbUseTVMenuLanguage, val); - SetControlEnabled(cbPowerOnStartup, val); - SetControlEnabled(cbPowerOffShutdown, val); + SetControlEnabled(cbActivateSource, val); SetControlEnabled(cbPowerOffScreensaver, val); SetControlEnabled(cbPowerOffOnStandby, val); SetControlEnabled(cbWakeDevices, false); // TODO not implemented yet + SetControlEnabled(cbPowerOffDevices, false); // TODO not implemented yet + SetControlEnabled(cbVendorOverride, false); // TODO not implemented yet + SetControlEnabled(cbVendorId, false); // TODO not implemented yet SetControlEnabled(bClose, val); SetControlEnabled(bSave, val); @@ -375,196 +397,40 @@ namespace CecConfigGui SetControlEnabled(bMute, enableVolumeButtons); } - delegate void SetControlTextCallback(Control control, string val); - private void SetControlText(Control control, string val) + #region Configuration tab + private void tbPhysicalAddress_TextChanged(object sender, EventArgs e) { - if (control.InvokeRequired) - { - SetControlTextCallback d = new SetControlTextCallback(SetControlText); - try - { - this.Invoke(d, new object[] { control, val }); - } - catch (Exception) { } - } - else - { - control.Text = val; - } + if (tbPhysicalAddress.Text.Length != 4) + return; + ushort physicalAddress = 0; + if (!ushort.TryParse(tbPhysicalAddress.Text, NumberStyles.AllowHexSpecifier, null, out physicalAddress)) + return; + + SetPhysicalAddress(physicalAddress); } - delegate void SetCheckboxCheckedCallback(CheckBox control, bool val); - private void SetCheckboxChecked(CheckBox control, bool val) + private void UpdateSelectedDevice() { - if (control.InvokeRequired) - { - SetCheckboxCheckedCallback d = new SetCheckboxCheckedCallback(SetCheckboxChecked); - try - { - this.Invoke(d, new object[] { control, val }); - } - catch (Exception) { } - } + if (HasAVRDevice) + SetComboBoxItems(this.cbConnectedDevice, Config.BaseDevice == CecLogicalAddress.AudioSystem ? AVRVendorString : TVVendorString, new object[] { TVVendorString, AVRVendorString }); else - { - control.Checked = val; - } + SetComboBoxItems(this.cbConnectedDevice, TVVendorString, new object[] { TVVendorString }); } - delegate void SetProgressValueCallback(ProgressBar control, int val); - private void SetProgressValue(ProgressBar control, int val) + public void SetConnectedDevice(CecLogicalAddress address, int portnumber) { - if (control.InvokeRequired) - { - SetProgressValueCallback d = new SetProgressValueCallback(SetProgressValue); - try - { - this.Invoke(d, new object[] { control, val }); - } - catch (Exception) { } - } - else + if (!SuppressUpdates && ActiveProcess == null) { - control.Value = val; + SetControlsEnabled(false); + ActiveProcess = new UpdateConnectedDevice(ref Lib, address, portnumber); + ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); + (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); } } - delegate void SetComboBoxItemsCallback(ComboBox control, string selectedText, object[] val); - private void SetComboBoxItems(ComboBox control, string selectedText, object[] val) + private void connectedDevice_SelectedIndexChanged(object sender, EventArgs e) { - if (control.InvokeRequired) - { - SetComboBoxItemsCallback d = new SetComboBoxItemsCallback(SetComboBoxItems); - try - { - this.Invoke(d, new object[] { control, selectedText, val }); - } - catch (Exception) { } - } - else - { - control.Items.Clear(); - control.Items.AddRange(val); - control.Text = selectedText; - } - } - - private void ProcessEventHandler(object src, UpdateEvent updateEvent) - { - switch (updateEvent.Type) - { - case UpdateEventType.StatusText: - SetControlText(lStatus, updateEvent.StringValue); - break; - case UpdateEventType.PhysicalAddress: - Config.PhysicalAddress = (ushort)updateEvent.IntValue; - SetControlText(tbPhysicalAddress, string.Format("{0,4:X}", updateEvent.IntValue)); - break; - case UpdateEventType.ProgressBar: - SetProgressValue(pProgress, updateEvent.IntValue); - break; - case UpdateEventType.TVVendorId: - TVVendor = (CecVendorId)updateEvent.IntValue; - UpdateSelectedDevice(); - break; - case UpdateEventType.BaseDevicePhysicalAddress: - SetControlText(lConnectedPhysicalAddress, string.Format("Address: {0,4:X}", updateEvent.IntValue)); - break; - case UpdateEventType.BaseDevice: - Config.BaseDevice = (CecLogicalAddress)updateEvent.IntValue; - break; - case UpdateEventType.HDMIPort: - Config.HDMIPort = (byte)updateEvent.IntValue; - break; - case UpdateEventType.MenuLanguage: - SetControlText(cbUseTVMenuLanguage, "Use the TV's language setting" + (updateEvent.StringValue.Length > 0 ? " (" + updateEvent.StringValue + ")" : "")); - break; - case UpdateEventType.HasAVRDevice: - if (HasAVRDevice != updateEvent.BoolValue) - { - HasAVRDevice = updateEvent.BoolValue; - UpdateSelectedDevice(); - } - break; - case UpdateEventType.AVRVendorId: - AVRVendor = (CecVendorId)updateEvent.IntValue; - UpdateSelectedDevice(); - break; - case UpdateEventType.Configuration: - Config = updateEvent.ConfigValue; - SetControlText(tbPhysicalAddress, string.Format("{0,4:X}", Config.PhysicalAddress)); - SetControlText(cbConnectedDevice, Config.BaseDevice == CecLogicalAddress.AudioSystem ? AVRVendorString : TVVendorString); - SetControlText(cbPortNumber, Config.HDMIPort.ToString()); - SetCheckboxChecked(cbUseTVMenuLanguage, Config.UseTVMenuLanguage); - SetCheckboxChecked(cbPowerOnStartup, Config.PowerOnStartup); - SetCheckboxChecked(cbPowerOffShutdown, Config.PowerOffShutdown); - SetCheckboxChecked(cbPowerOffScreensaver, Config.PowerOffScreensaver); - SetCheckboxChecked(cbPowerOffOnStandby, Config.PowerOffOnStandby); - UpdateSelectedDevice(); - break; - case UpdateEventType.ProcessCompleted: - ActiveProcess = null; - SetControlsEnabled(true); - break; - } - } - - private void UpdateSelectedDevice() - { - if (HasAVRDevice) - SetComboBoxItems(this.cbConnectedDevice, Config.BaseDevice == CecLogicalAddress.AudioSystem ? AVRVendorString : TVVendorString, new object[] { TVVendorString, AVRVendorString }); - else - SetComboBoxItems(this.cbConnectedDevice, TVVendorString, new object[] { TVVendorString }); - } - - public string TVVendorString - { - get - { - return TVVendor != CecVendorId.Unknown ? - "Television (" + Lib.ToString(TVVendor) + ")" : - "Television"; - } - } - - public string AVRVendorString - { - get - { - return AVRVendor != CecVendorId.Unknown ? - "AVR (" + Lib.ToString(AVRVendor) + ")" : - "AVR"; - } - } - - protected bool HasAVRDevice; - protected CecVendorId TVVendor = CecVendorId.Unknown; - protected CecVendorId AVRVendor = CecVendorId.Unknown; - protected CecLogicalAddress SelectedConnectedDevice = CecLogicalAddress.Unknown; - - protected LibCECConfiguration Config; - protected LibCecSharp Lib; - private CecCallbackWrapper Callbacks; - private UpdateProcess ActiveProcess = null; - - public void SetConnectedDevice(CecLogicalAddress address, int portnumber) - { - if (ActiveProcess == null) - { - SetControlsEnabled(false); - ActiveProcess = new UpdateConnectedDevice(ref Lib, address, portnumber); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); - } - } - - private void connectedDevice_SelectedIndexChanged(object sender, EventArgs e) - { - SelectedConnectedDevice = (this.cbConnectedDevice.Text.Equals(AVRVendorString)) ? CecLogicalAddress.AudioSystem : CecLogicalAddress.Tv; - int iPortNumber = 0; - if (!int.TryParse(cbPortNumber.Text, out iPortNumber)) - iPortNumber = 1; - SetConnectedDevice(SelectedConnectedDevice, iPortNumber); + SetConnectedDevice(SelectedConnectedDevice, SelectedPortNumber); } private void bCancel_Click(object sender, EventArgs e) @@ -577,8 +443,7 @@ namespace CecConfigGui SetControlsEnabled(false); Config.UseTVMenuLanguage = cbUseTVMenuLanguage.Checked; - Config.PowerOnStartup = cbPowerOnStartup.Checked; - Config.PowerOffShutdown = cbPowerOffShutdown.Checked; + Config.ActivateSource = cbActivateSource.Checked; Config.PowerOffScreensaver = cbPowerOffScreensaver.Checked; Config.PowerOffOnStandby = cbPowerOffOnStandby.Checked; @@ -613,15 +478,31 @@ namespace CecConfigGui output.AppendLine(""); output.AppendLine(""); output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); output.AppendLine(""); output.AppendLine(""); output.AppendLine(""); output.AppendLine(""); output.AppendLine(""); + + // only supported by 1.5.0+ clients + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + + output.Append(""); + + output.Append(""); + output.AppendLine(""); writer.Write(output.ToString()); writer.Close(); @@ -642,63 +523,40 @@ namespace CecConfigGui } SetControlsEnabled(true); } + #endregion - public void SetPhysicalAddress(ushort physicalAddress) - { - if (ActiveProcess == null) - { - SetControlsEnabled(false); - SetControlText(cbPortNumber, string.Empty); - SetControlText(cbConnectedDevice, string.Empty); - ActiveProcess = new UpdatePhysicalAddress(ref Lib, physicalAddress); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); - } - } - - private void tbPhysicalAddress_TextChanged(object sender, EventArgs e) - { - if (tbPhysicalAddress.Text.Length != 4) - return; - ushort physicalAddress = 0; - if (!ushort.TryParse(tbPhysicalAddress.Text, NumberStyles.AllowHexSpecifier, null, out physicalAddress)) - return; - - SetPhysicalAddress(physicalAddress); - } - - private void bClearLog_Click(object sender, EventArgs e) - { - tbLog.Text = string.Empty; - } - - private void bSaveLog_Click(object sender, EventArgs e) + #region Key configuration tab + delegate void SelectKeypressRowCallback(CecKeypress key); + private void SelectKeypressRow(CecKeypress key) { - SaveFileDialog dialog = new SaveFileDialog() - { - Title = "Where do you want to store the log file?", - InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), - FileName = "cec-log.txt", - Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*", - FilterIndex = 1 - }; - - if (dialog.ShowDialog() == DialogResult.OK) + if (dgButtons.InvokeRequired) { - FileStream fs = (FileStream)dialog.OpenFile(); - if (fs == null) + SelectKeypressRowCallback d = new SelectKeypressRowCallback(SelectKeypressRow); + try { - MessageBox.Show("Cannot open '" + dialog.FileName + "' for writing", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error); + this.Invoke(d, new object[] { key }); } - else + catch (Exception) { } + } + else + { + int rowIndex = -1; + foreach (DataGridViewRow row in dgButtons.Rows) { - StreamWriter writer = new StreamWriter(fs); - writer.Write(tbLog.Text); - writer.Close(); - fs.Close(); - fs.Dispose(); - MessageBox.Show("The log file was stored as '" + dialog.FileName + "'.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Information); + CecButtonConfigItem item = row.DataBoundItem as CecButtonConfigItem; + if (item != null && item.Key.Keycode == key.Keycode) + { + rowIndex = row.Index; + row.Selected = true; + item.Enabled = true; + } + else + { + row.Selected = false; + } } + if (rowIndex > -1) + dgButtons.FirstDisplayedScrollingRowIndex = rowIndex; } } @@ -709,7 +567,9 @@ namespace CecConfigGui if (data == null || !data.Enabled) e.CellStyle.ForeColor = Color.Gray; } + #endregion + #region CEC Tester tab delegate CecLogicalAddress GetTargetDeviceCallback(); private CecLogicalAddress GetTargetDevice() { @@ -764,65 +624,21 @@ namespace CecConfigGui } } - public void SendImageViewOn(CecLogicalAddress address) - { - if (ActiveProcess == null) - { - SetControlsEnabled(false); - ActiveProcess = new SendImageViewOn(ref Lib, address); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); - } - } - private void bSendImageViewOn_Click(object sender, EventArgs e) { SendImageViewOn(GetTargetDevice()); } - public void SendStandby(CecLogicalAddress address) - { - if (ActiveProcess == null) - { - SetControlsEnabled(false); - ActiveProcess = new SendStandby(ref Lib, address); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); - } - } - private void bStandby_Click(object sender, EventArgs e) { SendStandby(GetTargetDevice()); } - public void ShowDeviceInfo(CecLogicalAddress address) - { - if (ActiveProcess == null) - { - SetControlsEnabled(false); - ActiveProcess = new ShowDeviceInfo(this, ref Lib, address); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); - } - } - private void bScan_Click(object sender, EventArgs e) { ShowDeviceInfo(GetTargetDevice()); } - public void ActivateSource(CecLogicalAddress address) - { - if (ActiveProcess == null) - { - SetControlsEnabled(false); - ActiveProcess = new SendActivateSource(ref Lib, address); - ActiveProcess.EventHandler += new EventHandler(ProcessEventHandler); - (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); - } - } - private void bActivateSource_Click(object sender, EventArgs e) { ActivateSource(GetTargetDevice()); @@ -856,8 +672,194 @@ namespace CecConfigGui Lib.MuteAudio(true); SetControlsEnabled(true); } + #endregion + + #region Log tab + delegate void AddLogMessageCallback(CecLogMessage message); + private void AddLogMessage(CecLogMessage message) + { + if (tbLog.InvokeRequired) + { + AddLogMessageCallback d = new AddLogMessageCallback(AddLogMessage); + try + { + this.Invoke(d, new object[] { message }); + } + catch (Exception) { } + } + else + { + string strLevel = ""; + bool display = false; + switch (message.Level) + { + case CecLogLevel.Error: + strLevel = "ERROR: "; + display = cbLogError.Checked; + break; + case CecLogLevel.Warning: + strLevel = "WARNING: "; + display = cbLogWarning.Checked; + break; + case CecLogLevel.Notice: + strLevel = "NOTICE: "; + display = cbLogNotice.Checked; + break; + case CecLogLevel.Traffic: + strLevel = "TRAFFIC: "; + display = cbLogTraffic.Checked; + break; + case CecLogLevel.Debug: + strLevel = "DEBUG: "; + display = cbLogDebug.Checked; + break; + default: + break; + } + + if (display) + { + string strLog = string.Format("{0} {1,16} {2}", strLevel, message.Time, message.Message) + System.Environment.NewLine; + tbLog.Text += strLog; + tbLog.Select(tbLog.Text.Length, 0); + tbLog.ScrollToCaret(); + } + } + } + + private void bClearLog_Click(object sender, EventArgs e) + { + tbLog.Text = string.Empty; + } + + private void bSaveLog_Click(object sender, EventArgs e) + { + SaveFileDialog dialog = new SaveFileDialog() + { + Title = "Where do you want to store the log file?", + InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), + FileName = "cec-log.txt", + Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*", + FilterIndex = 1 + }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + FileStream fs = (FileStream)dialog.OpenFile(); + if (fs == null) + { + MessageBox.Show("Cannot open '" + dialog.FileName + "' for writing", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + StreamWriter writer = new StreamWriter(fs); + writer.Write(tbLog.Text); + writer.Close(); + fs.Close(); + fs.Dispose(); + MessageBox.Show("The log file was stored as '" + dialog.FileName + "'.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + #endregion + + #region LibCecSharp callbacks + public int ConfigurationChanged(LibCECConfiguration config) + { + Config = config; + SetControlText(tbPhysicalAddress, string.Format("{0,4:X}", Config.PhysicalAddress)); + SetControlText(cbConnectedDevice, Config.BaseDevice == CecLogicalAddress.AudioSystem ? AVRVendorString : TVVendorString); + SetControlText(cbPortNumber, Config.HDMIPort.ToString()); + SetCheckboxChecked(cbUseTVMenuLanguage, Config.UseTVMenuLanguage); + SetCheckboxChecked(cbActivateSource, Config.ActivateSource); + SetCheckboxChecked(cbPowerOffScreensaver, Config.PowerOffScreensaver); + SetCheckboxChecked(cbPowerOffOnStandby, Config.PowerOffOnStandby); + UpdateSelectedDevice(); + return 1; + } + + public int ReceiveCommand(CecCommand command) + { + return 1; + } + + public int ReceiveKeypress(CecKeypress key) + { + SelectKeypressRow(key); + return 1; + } + + public int ReceiveLogMessage(CecLogMessage message) + { + AddLogMessage(message); + return 1; + } + #endregion + + #region Class members + public bool HasAVRDevice { get; private set; } + #region TV Vendor + private CecVendorId _tvVendor = CecVendorId.Unknown; + public CecVendorId TVVendor + { + get { return _tvVendor;} + private set { _tvVendor = value; } + } + public string TVVendorString + { + get + { + return TVVendor != CecVendorId.Unknown ? + "Television (" + Lib.ToString(TVVendor) + ")" : + "Television"; + } + } + #endregion + #region AVR Vendor + private CecVendorId _avrVendor = CecVendorId.Unknown; + public CecVendorId AVRVendor + { + get { return _avrVendor; } + private set { _avrVendor = value; } + } + public string AVRVendorString + { + get + { + return AVRVendor != CecVendorId.Unknown ? + "AVR (" + Lib.ToString(AVRVendor) + ")" : + "AVR"; + } + } + #endregion + public CecLogicalAddress SelectedConnectedDevice + { + get + { + return (cbConnectedDevice.Text.Equals(AVRVendorString)) ? CecLogicalAddress.AudioSystem : CecLogicalAddress.Tv; + } + } + public int SelectedPortNumber + { + get + { + int iPortNumber = 0; + if (!int.TryParse(cbPortNumber.Text, out iPortNumber)) + iPortNumber = 1; + return iPortNumber; + } + } + protected LibCECConfiguration Config; + protected LibCecSharp Lib; + private CecCallbackWrapper Callbacks; + private UpdateProcess ActiveProcess = null; + private bool SuppressUpdates = false; + #endregion } + /// + /// A little wrapper that is needed because we already inherit form + /// internal class CecCallbackWrapper : CecCallbackMethods { public CecCallbackWrapper(CecConfigGUI gui) diff --git a/src/cec-config-gui/CecConfigGUI.resx b/src/cec-config-gui/CecConfigGUI.resx index c49183f..b3aad3e 100644 --- a/src/cec-config-gui/CecConfigGUI.resx +++ b/src/cec-config-gui/CecConfigGUI.resx @@ -135,4 +135,19 @@ 662, 17 + + True + + + 662, 17 + + + 17, 17 + + + 160, 17 + + + 362, 17 + \ No newline at end of file diff --git a/src/cec-config-gui/DeviceInformation.cs b/src/cec-config-gui/DeviceInformation.cs index d340e47..2900ab3 100644 --- a/src/cec-config-gui/DeviceInformation.cs +++ b/src/cec-config-gui/DeviceInformation.cs @@ -9,7 +9,7 @@ using CecSharp; namespace CecConfigGui { - public partial class DeviceInformation : Form + public partial class DeviceInformation : AsyncForm { public DeviceInformation(CecConfigGUI gui, CecLogicalAddress address, ref LibCecSharp lib, bool devicePresent, CecVendorId vendor, bool isActiveSource, ushort physicalAddress, @@ -34,42 +34,6 @@ namespace CecConfigGui this.Text = "Device: " + osdName; } - delegate void SetControlVisibleCallback(Control control, bool val); - private void SetControlVisible(Control control, bool val) - { - if (control.InvokeRequired) - { - SetControlVisibleCallback d = new SetControlVisibleCallback(SetControlVisible); - try - { - this.Invoke(d, new object[] { control, val }); - } - catch (Exception) { } - } - else - { - control.Visible = val; - } - } - - delegate void SetControlTextCallback(Control control, string val); - private void SetControlText(Control control, string val) - { - if (control.InvokeRequired) - { - SetControlTextCallback d = new SetControlTextCallback(SetControlText); - try - { - this.Invoke(d, new object[] { control, val }); - } - catch (Exception) { } - } - else - { - control.Text = val; - } - } - private void lInactiveSource_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { SetControlVisible(lInactiveSource, false); @@ -77,7 +41,6 @@ namespace CecConfigGui Gui.ActivateSource(Address); } - private void lStandby_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { LinkLabel label = sender as LinkLabel; diff --git a/src/cec-config-gui/cec-config-gui.csproj b/src/cec-config-gui/cec-config-gui.csproj index 4b83aaa..3594a16 100644 --- a/src/cec-config-gui/cec-config-gui.csproj +++ b/src/cec-config-gui/cec-config-gui.csproj @@ -61,6 +61,9 @@ + + Form + Form