cec-config-gui: added log level configuration and a 'save' and 'clear' button for...
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 14 Feb 2012 11:42:13 +0000 (12:42 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 14 Feb 2012 11:42:13 +0000 (12:42 +0100)
src/cec-config-gui/CecConfigGUI.Designer.cs
src/cec-config-gui/CecConfigGUI.cs
src/cec-config-gui/CecConfigGUI.resx

index d328816572c03a195ad30cbc2b0a9442e78a01d2..cdbc43c3de1e46adde32957ac4b9672797c810e7 100644 (file)
       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.LogOutput = new System.Windows.Forms.TabPage();
+      this.bClearLog = new System.Windows.Forms.Button();
+      this.cbLogDebug = new System.Windows.Forms.CheckBox();
+      this.cbLogTraffic = new System.Windows.Forms.CheckBox();
+      this.cbLogNotice = new System.Windows.Forms.CheckBox();
+      this.cbLogWarning = new System.Windows.Forms.CheckBox();
+      this.cbLogError = new System.Windows.Forms.CheckBox();
       this.tbLog = new System.Windows.Forms.TextBox();
       this.pProgress = new System.Windows.Forms.ProgressBar();
       this.lStatus = new System.Windows.Forms.Label();
@@ -57,6 +64,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.bSaveLog = new System.Windows.Forms.Button();
       this.tabControl1.SuspendLayout();
       this.Configuration.SuspendLayout();
       this.LogOutput.SuspendLayout();
@@ -65,6 +73,7 @@
       // tabControl1
       // 
       this.tabControl1.Controls.Add(this.Configuration);
+      this.tabControl1.Controls.Add(this.tbButtons);
       this.tabControl1.Controls.Add(this.LogOutput);
       this.tabControl1.Location = new System.Drawing.Point(12, 12);
       this.tabControl1.Name = "tabControl1";
       this.lPortNumber.TabIndex = 0;
       this.lPortNumber.Text = "HDMI Port number";
       // 
+      // tbButtons
+      // 
+      this.tbButtons.Location = new System.Drawing.Point(4, 22);
+      this.tbButtons.Name = "tbButtons";
+      this.tbButtons.Padding = new System.Windows.Forms.Padding(3);
+      this.tbButtons.Size = new System.Drawing.Size(592, 359);
+      this.tbButtons.TabIndex = 2;
+      this.tbButtons.Text = "Button Configuration";
+      this.tbButtons.UseVisualStyleBackColor = true;
+      // 
       // LogOutput
       // 
+      this.LogOutput.Controls.Add(this.bSaveLog);
+      this.LogOutput.Controls.Add(this.bClearLog);
+      this.LogOutput.Controls.Add(this.cbLogDebug);
+      this.LogOutput.Controls.Add(this.cbLogTraffic);
+      this.LogOutput.Controls.Add(this.cbLogNotice);
+      this.LogOutput.Controls.Add(this.cbLogWarning);
+      this.LogOutput.Controls.Add(this.cbLogError);
       this.LogOutput.Controls.Add(this.tbLog);
       this.LogOutput.Location = new System.Drawing.Point(4, 22);
       this.LogOutput.Name = "LogOutput";
       this.LogOutput.Text = "Log Output";
       this.LogOutput.UseVisualStyleBackColor = true;
       // 
+      // bClearLog
+      // 
+      this.bClearLog.Location = new System.Drawing.Point(511, 330);
+      this.bClearLog.Name = "bClearLog";
+      this.bClearLog.Size = new System.Drawing.Size(75, 23);
+      this.bClearLog.TabIndex = 6;
+      this.bClearLog.Text = "Clear";
+      this.bClearLog.UseVisualStyleBackColor = true;
+      this.bClearLog.Click += new System.EventHandler(this.bClearLog_Click);
+      // 
+      // cbLogDebug
+      // 
+      this.cbLogDebug.AutoSize = true;
+      this.cbLogDebug.Location = new System.Drawing.Point(269, 336);
+      this.cbLogDebug.Name = "cbLogDebug";
+      this.cbLogDebug.Size = new System.Drawing.Size(58, 17);
+      this.cbLogDebug.TabIndex = 5;
+      this.cbLogDebug.Text = "Debug";
+      this.cbLogDebug.UseVisualStyleBackColor = true;
+      // 
+      // cbLogTraffic
+      // 
+      this.cbLogTraffic.AutoSize = true;
+      this.cbLogTraffic.Location = new System.Drawing.Point(207, 336);
+      this.cbLogTraffic.Name = "cbLogTraffic";
+      this.cbLogTraffic.Size = new System.Drawing.Size(56, 17);
+      this.cbLogTraffic.TabIndex = 4;
+      this.cbLogTraffic.Text = "Traffic";
+      this.cbLogTraffic.UseVisualStyleBackColor = true;
+      // 
+      // cbLogNotice
+      // 
+      this.cbLogNotice.AutoSize = true;
+      this.cbLogNotice.Checked = true;
+      this.cbLogNotice.CheckState = System.Windows.Forms.CheckState.Checked;
+      this.cbLogNotice.Location = new System.Drawing.Point(138, 336);
+      this.cbLogNotice.Name = "cbLogNotice";
+      this.cbLogNotice.Size = new System.Drawing.Size(62, 17);
+      this.cbLogNotice.TabIndex = 3;
+      this.cbLogNotice.Text = "Notices";
+      this.cbLogNotice.UseVisualStyleBackColor = true;
+      // 
+      // cbLogWarning
+      // 
+      this.cbLogWarning.AutoSize = true;
+      this.cbLogWarning.Checked = true;
+      this.cbLogWarning.CheckState = System.Windows.Forms.CheckState.Checked;
+      this.cbLogWarning.Location = new System.Drawing.Point(66, 336);
+      this.cbLogWarning.Name = "cbLogWarning";
+      this.cbLogWarning.Size = new System.Drawing.Size(66, 17);
+      this.cbLogWarning.TabIndex = 2;
+      this.cbLogWarning.Text = "Warning";
+      this.cbLogWarning.UseVisualStyleBackColor = true;
+      // 
+      // cbLogError
+      // 
+      this.cbLogError.AutoSize = true;
+      this.cbLogError.Checked = true;
+      this.cbLogError.CheckState = System.Windows.Forms.CheckState.Checked;
+      this.cbLogError.Location = new System.Drawing.Point(7, 336);
+      this.cbLogError.Name = "cbLogError";
+      this.cbLogError.Size = new System.Drawing.Size(53, 17);
+      this.cbLogError.TabIndex = 1;
+      this.cbLogError.Text = "Errors";
+      this.cbLogError.UseVisualStyleBackColor = true;
+      // 
       // tbLog
       // 
       this.tbLog.Location = new System.Drawing.Point(6, 6);
       this.tbLog.Multiline = true;
       this.tbLog.Name = "tbLog";
       this.tbLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
-      this.tbLog.Size = new System.Drawing.Size(580, 347);
+      this.tbLog.Size = new System.Drawing.Size(580, 318);
       this.tbLog.TabIndex = 0;
       // 
       // pProgress
       this.lStatus.TabIndex = 2;
       this.lStatus.Text = "Initialising...";
       // 
+      // bSaveLog
+      // 
+      this.bSaveLog.Location = new System.Drawing.Point(430, 330);
+      this.bSaveLog.Name = "bSaveLog";
+      this.bSaveLog.Size = new System.Drawing.Size(75, 23);
+      this.bSaveLog.TabIndex = 7;
+      this.bSaveLog.Text = "Save";
+      this.bSaveLog.UseVisualStyleBackColor = true;
+      this.bSaveLog.Click += new System.EventHandler(this.bSaveLog_Click);
+      // 
       // CecConfigGUI
       // 
       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     private System.Windows.Forms.ToolTip helpConnectedHDMIDevice;
     private System.Windows.Forms.ToolTip helpDeviceType;
     private System.Windows.Forms.ToolTip helpPhysicalAddress;
+    private System.Windows.Forms.TabPage tbButtons;
+    private System.Windows.Forms.CheckBox cbLogDebug;
+    private System.Windows.Forms.CheckBox cbLogTraffic;
+    private System.Windows.Forms.CheckBox cbLogNotice;
+    private System.Windows.Forms.CheckBox cbLogWarning;
+    private System.Windows.Forms.CheckBox cbLogError;
+    private System.Windows.Forms.Button bClearLog;
+    private System.Windows.Forms.Button bSaveLog;
   }
 }
\ No newline at end of file
index f2a4760196bb841524db88128b11072e5924bd74..800cd425e1877197d7c186757594a0f7c940ae00 100644 (file)
@@ -57,31 +57,40 @@ namespace CecConfigGui
       }
       else
       {
-        if (((int)message.Level & LogLevel) == (int)message.Level)
+        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 strLevel = "";
-          switch (message.Level)
-          {
-            case CecLogLevel.Error:
-              strLevel = "ERROR:   ";
-              break;
-            case CecLogLevel.Warning:
-              strLevel = "WARNING: ";
-              break;
-            case CecLogLevel.Notice:
-              strLevel = "NOTICE:  ";
-              break;
-            case CecLogLevel.Traffic:
-              strLevel = "TRAFFIC: ";
-              break;
-            case CecLogLevel.Debug:
-              strLevel = "DEBUG:   ";
-              break;
-            default:
-              break;
-          }
           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();
         }
       }
     }
@@ -291,7 +300,6 @@ namespace CecConfigGui
     protected CecVendorId TVVendor = CecVendorId.Unknown;
     protected CecVendorId AVRVendor = CecVendorId.Unknown;
     protected CecLogicalAddress SelectedConnectedDevice = CecLogicalAddress.Unknown;
-    protected int LogLevel = (int)CecLogLevel.All;
 
     protected LibCECConfiguration Config;
     protected LibCecSharp Lib;
@@ -406,6 +414,41 @@ namespace CecConfigGui
         (new Thread(new ThreadStart(ActiveProcess.Run))).Start();
       }
     }
+
+    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);
+        }
+      }
+    }
   }
 
   internal class CecCallbackWrapper : CecCallbackMethods
index 5d3dca48b4fb3786f387ba1b98efac9bf850bfd9..da39715b14b00b2fafb47d4c06b8e72ddfd99380 100644 (file)
   <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="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>
 </root>
\ No newline at end of file