From: Lars Op den Kamp Date: Wed, 15 Feb 2012 18:39:40 +0000 (+0100) Subject: cec-config-gui: don't update the log window all the time when it's not the selected tab X-Git-Tag: upstream/2.2.0~1^2~35^2~37 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;ds=inline;h=5de1dde470c394fc45791fbb747fdf8ad6e73b2a;p=deb_libcec.git cec-config-gui: don't update the log window all the time when it's not the selected tab --- diff --git a/src/cec-config-gui/CecConfigGUI.Designer.cs b/src/cec-config-gui/CecConfigGUI.Designer.cs index 9b22679..2489cf2 100644 --- a/src/cec-config-gui/CecConfigGUI.Designer.cs +++ b/src/cec-config-gui/CecConfigGUI.Designer.cs @@ -32,6 +32,7 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CecConfigGUI)); this.tabControl1 = new System.Windows.Forms.TabControl(); this.Configuration = new System.Windows.Forms.TabPage(); + this.bReloadConfig = new System.Windows.Forms.Button(); this.cbVendorOverride = new System.Windows.Forms.CheckBox(); this.cbVendorId = new System.Windows.Forms.ComboBox(); this.lPowerOff = new System.Windows.Forms.Label(); @@ -46,7 +47,7 @@ this.lAdapterConfig = new System.Windows.Forms.Label(); this.cbDeviceType = new System.Windows.Forms.ComboBox(); this.bClose = new System.Windows.Forms.Button(); - this.bSave = 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(); @@ -106,9 +107,11 @@ this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(600, 385); this.tabControl1.TabIndex = 0; + this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged); // // Configuration // + this.Configuration.Controls.Add(this.bReloadConfig); this.Configuration.Controls.Add(this.cbVendorOverride); this.Configuration.Controls.Add(this.cbVendorId); this.Configuration.Controls.Add(this.lPowerOff); @@ -123,7 +126,7 @@ this.Configuration.Controls.Add(this.lAdapterConfig); this.Configuration.Controls.Add(this.cbDeviceType); this.Configuration.Controls.Add(this.bClose); - this.Configuration.Controls.Add(this.bSave); + this.Configuration.Controls.Add(this.bSaveConfig); this.Configuration.Controls.Add(this.cbPortNumber); this.Configuration.Controls.Add(this.lConnectedPhysicalAddress); this.Configuration.Controls.Add(this.tbPhysicalAddress); @@ -140,6 +143,17 @@ this.Configuration.Text = "Configuration"; this.Configuration.UseVisualStyleBackColor = true; // + // bReloadConfig + // + this.bReloadConfig.Enabled = false; + this.bReloadConfig.Location = new System.Drawing.Point(358, 330); + this.bReloadConfig.Name = "bReloadConfig"; + this.bReloadConfig.Size = new System.Drawing.Size(125, 23); + this.bReloadConfig.TabIndex = 30; + this.bReloadConfig.Text = "Reload configuration"; + this.bReloadConfig.UseVisualStyleBackColor = true; + this.bReloadConfig.Click += new System.EventHandler(this.bReloadConfig_Click); + // // cbVendorOverride // this.cbVendorOverride.AutoSize = true; @@ -322,24 +336,24 @@ // bClose // this.bClose.Enabled = false; - this.bClose.Location = new System.Drawing.Point(189, 330); + this.bClose.Location = new System.Drawing.Point(96, 330); this.bClose.Name = "bClose"; - this.bClose.Size = new System.Drawing.Size(75, 23); + this.bClose.Size = new System.Drawing.Size(125, 23); this.bClose.TabIndex = 13; this.bClose.Text = "Close"; this.bClose.UseVisualStyleBackColor = true; this.bClose.Click += new System.EventHandler(this.bCancel_Click); // - // bSave + // bSaveConfig // - this.bSave.Enabled = false; - this.bSave.Location = new System.Drawing.Point(298, 330); - this.bSave.Name = "bSave"; - this.bSave.Size = new System.Drawing.Size(125, 23); - this.bSave.TabIndex = 12; - this.bSave.Text = "Save configuration"; - this.bSave.UseVisualStyleBackColor = true; - this.bSave.Click += new System.EventHandler(this.bSave_Click); + this.bSaveConfig.Enabled = false; + this.bSaveConfig.Location = new System.Drawing.Point(227, 330); + this.bSaveConfig.Name = "bSaveConfig"; + this.bSaveConfig.Size = new System.Drawing.Size(125, 23); + this.bSaveConfig.TabIndex = 12; + this.bSaveConfig.Text = "Save configuration"; + this.bSaveConfig.UseVisualStyleBackColor = true; + this.bSaveConfig.Click += new System.EventHandler(this.bSave_Click); // // cbPortNumber // @@ -786,7 +800,7 @@ private System.Windows.Forms.TextBox tbLog; private System.Windows.Forms.ComboBox cbPortNumber; private System.Windows.Forms.Button bClose; - private System.Windows.Forms.Button bSave; + private System.Windows.Forms.Button bSaveConfig; private System.Windows.Forms.ComboBox cbDeviceType; private System.Windows.Forms.Label lAdapterConfig; private System.Windows.Forms.CheckBox cbPowerOffOnStandby; @@ -827,5 +841,6 @@ private System.Windows.Forms.CheckedListBox cbPowerOffDevices; private System.Windows.Forms.CheckBox cbVendorOverride; private System.Windows.Forms.ComboBox cbVendorId; + private System.Windows.Forms.Button bReloadConfig; } } \ No newline at end of file diff --git a/src/cec-config-gui/CecConfigGUI.cs b/src/cec-config-gui/CecConfigGUI.cs index 83a83ac..943ca2e 100644 --- a/src/cec-config-gui/CecConfigGUI.cs +++ b/src/cec-config-gui/CecConfigGUI.cs @@ -14,6 +14,14 @@ using System.Xml; namespace CecConfigGui { + internal enum ConfigTab + { + Configuration, + KeyConfiguration, + Tester, + Log + } + public partial class CecConfigGUI : AsyncForm { public CecConfigGUI() @@ -312,6 +320,66 @@ namespace CecConfigGui } } + private void SetControlsEnabled(bool val) + { + SetControlEnabled(cbPortNumber, val); + SetControlEnabled(cbConnectedDevice, cbConnectedDevice.Items.Count > 1 ? val : false); + SetControlEnabled(tbPhysicalAddress, val); + SetControlEnabled(cbDeviceType, false); // TODO not implemented yet + SetControlEnabled(cbUseTVMenuLanguage, 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, val); + SetControlEnabled(cbVendorId, val && cbVendorOverride.Checked); + SetControlEnabled(bClose, val); + SetControlEnabled(bSaveConfig, val); + SetControlEnabled(bReloadConfig, val); + + SetControlEnabled(bSendImageViewOn, val); + SetControlEnabled(bStandby, val); + SetControlEnabled(bActivateSource, val); + SetControlEnabled(bScan, val); + + bool enableVolumeButtons = (GetTargetDevice() == CecLogicalAddress.AudioSystem) && val; + SetControlEnabled(bVolUp, enableVolumeButtons); + SetControlEnabled(bVolDown, enableVolumeButtons); + SetControlEnabled(bMute, enableVolumeButtons); + } + + private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) + { + switch (tabControl1.SelectedIndex) + { + case 0: + SelectedTab = ConfigTab.Configuration; + break; + case 1: + SelectedTab = ConfigTab.KeyConfiguration; + break; + case 2: + SelectedTab = ConfigTab.Tester; + break; + case 3: + SelectedTab = ConfigTab.Log; + UpdateLog(); + break; + default: + SelectedTab = ConfigTab.Configuration; + break; + } + } + + #region Actions + public void ReloadXMLConfiguration() + { + LoadXMLConfiguration(ref Config); + Lib.SetConfiguration(Config); + ConfigurationChanged(Config); + } + public void SetPhysicalAddress(ushort physicalAddress) { if (!SuppressUpdates && ActiveProcess == null) @@ -368,34 +436,7 @@ namespace CecConfigGui (new Thread(new ThreadStart(ActiveProcess.Run))).Start(); } } - - private void SetControlsEnabled(bool val) - { - SetControlEnabled(cbPortNumber, val); - SetControlEnabled(cbConnectedDevice, cbConnectedDevice.Items.Count > 1 ? val : false); - SetControlEnabled(tbPhysicalAddress, val); - SetControlEnabled(cbDeviceType, false); // TODO not implemented yet - SetControlEnabled(cbUseTVMenuLanguage, 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, val); - SetControlEnabled(cbVendorId, val && cbVendorOverride.Checked); - SetControlEnabled(bClose, val); - SetControlEnabled(bSave, val); - - SetControlEnabled(bSendImageViewOn, val); - SetControlEnabled(bStandby, val); - SetControlEnabled(bActivateSource, val); - SetControlEnabled(bScan, val); - - bool enableVolumeButtons = (GetTargetDevice() == CecLogicalAddress.AudioSystem) && val; - SetControlEnabled(bVolUp, enableVolumeButtons); - SetControlEnabled(bVolDown, enableVolumeButtons); - SetControlEnabled(bMute, enableVolumeButtons); - } + #endregion #region Configuration tab private void tbPhysicalAddress_TextChanged(object sender, EventArgs e) @@ -533,6 +574,19 @@ namespace CecConfigGui SetControlsEnabled(true); } + private void bReloadConfig_Click(object sender, EventArgs e) + { + if (Lib.CanPersistConfiguration()) + { + Lib.GetCurrentConfiguration(Config); + ConfigurationChanged(Config); + } + else + { + ReloadXMLConfiguration(); + } + } + private void cbVendorOverride_CheckedChanged(object sender, EventArgs e) { if (cbVendorOverride.Checked) @@ -727,56 +781,64 @@ namespace CecConfigGui #endregion #region Log tab - delegate void AddLogMessageCallback(CecLogMessage message); - private void AddLogMessage(CecLogMessage message) + delegate void UpdateLogCallback(); + private void UpdateLog() { if (tbLog.InvokeRequired) { - AddLogMessageCallback d = new AddLogMessageCallback(AddLogMessage); + UpdateLogCallback d = new UpdateLogCallback(UpdateLog); try { - this.Invoke(d, new object[] { message }); + this.Invoke(d, new object[] { }); } 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; - } + tbLog.Text = Log; + tbLog.Select(tbLog.Text.Length, 0); + tbLog.ScrollToCaret(); + } + } - 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 AddLogMessage(CecLogMessage message) + { + 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; + Log += strLog; } + + if (SelectedTab == ConfigTab.Log) + UpdateLog(); } private void bClearLog_Click(object sender, EventArgs e) @@ -932,6 +994,8 @@ namespace CecConfigGui private CecCallbackWrapper Callbacks; private UpdateProcess ActiveProcess = null; private bool SuppressUpdates = false; + private ConfigTab SelectedTab = ConfigTab.Configuration; + private string Log = string.Empty; #endregion } diff --git a/src/cec-config-gui/CecConfigGUI.resx b/src/cec-config-gui/CecConfigGUI.resx index 98ad4dc..2efbf94 100644 --- a/src/cec-config-gui/CecConfigGUI.resx +++ b/src/cec-config-gui/CecConfigGUI.resx @@ -135,24 +135,6 @@ 662, 17 - - True - - - 662, 17 - - - 17, 17 - - - 160, 17 - - - 362, 17 - - - 524, 17 -