cec-config-gui: don't update the log window all the time when it's not the selected tab
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 15 Feb 2012 18:39:40 +0000 (19:39 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 15 Feb 2012 18:39:40 +0000 (19:39 +0100)
src/cec-config-gui/CecConfigGUI.Designer.cs
src/cec-config-gui/CecConfigGUI.cs
src/cec-config-gui/CecConfigGUI.resx

index 9b2267993c152b8cf7f9c9d2ecb711223a859bd4..2489cf25b2e584b8f8112b0c1d1ffe46914c1197 100644 (file)
@@ -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();
       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);
       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);
       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;
       // 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
       // 
     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;
     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
index 83a83ac43c9564fc93e4688a893fe5c9d9943075..943ca2e75fc14ef2bb19aa9706d9178b660fa629 100644 (file)
@@ -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
   }
 
index 98ad4dc68790de44a0e6aaa8b7d5db75d104ec30..2efbf9440b272f7b5f3b35b920eea33fca4cd3ad 100644 (file)
   <metadata name="cecButtonConfigBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>662, 17</value>
   </metadata>
-  <metadata name="CecButtonName.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="cecButtonConfigBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>662, 17</value>
-  </metadata>
-  <metadata name="helpPortNumber.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>17, 17</value>
-  </metadata>
-  <metadata name="helpConnectedHDMIDevice.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>160, 17</value>
-  </metadata>
-  <metadata name="helpPhysicalAddress.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>362, 17</value>
-  </metadata>
-  <metadata name="helpDeviceType.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>524, 17</value>
-  </metadata>
   <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>