cec-config-gui: added implementations for "wake devices" and "standby devices"
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 16 Feb 2012 00:59:44 +0000 (01:59 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 16 Feb 2012 00:59:44 +0000 (01:59 +0100)
src/cec-config-gui/AsyncForm.cs
src/cec-config-gui/CecConfigGUI.Designer.cs
src/cec-config-gui/CecConfigGUI.cs

index ab9afdd3ce7557b732a1827fe5845bf050345252..5898ce54be44112ecfc4da1341c7f930bd2fb6a6 100644 (file)
@@ -59,6 +59,24 @@ namespace CecConfigGui
       }
     }
 
+    delegate void SetCheckboxItemCheckedCallback(CheckedListBox control, int index, bool val);
+    public void SetCheckboxItemChecked(CheckedListBox control, int index, bool val)
+    {
+      if (control.InvokeRequired)
+      {
+        SetCheckboxItemCheckedCallback d = new SetCheckboxItemCheckedCallback(SetCheckboxItemChecked);
+        try
+        {
+          this.Invoke(d, new object[] { control, index, val });
+        }
+        catch (Exception) { }
+      }
+      else
+      {
+        control.SetItemChecked(index, val);
+      }
+    }
+
     delegate void SetProgressValueCallback(ProgressBar control, int val);
     public void SetProgressValue(ProgressBar control, int val)
     {
index 2c0f909e2ef9c573a5a31497dafa7bf74c88d63e..ca42375490083b0e5cf6a77a38ab1633343a67f2 100644 (file)
       // cbLogDebug
       // 
       this.cbLogDebug.AutoSize = true;
+      this.cbLogDebug.Checked = true;
+      this.cbLogDebug.CheckState = System.Windows.Forms.CheckState.Checked;
       this.cbLogDebug.Location = new System.Drawing.Point(269, 336);
       this.cbLogDebug.Name = "cbLogDebug";
       this.cbLogDebug.Size = new System.Drawing.Size(58, 17);
       // cbLogTraffic
       // 
       this.cbLogTraffic.AutoSize = true;
+      this.cbLogTraffic.Checked = true;
+      this.cbLogTraffic.CheckState = System.Windows.Forms.CheckState.Checked;
       this.cbLogTraffic.Location = new System.Drawing.Point(207, 336);
       this.cbLogTraffic.Name = "cbLogTraffic";
       this.cbLogTraffic.Size = new System.Drawing.Size(56, 17);
index 2bafae814b45e2867bf1240781791f29f0afdca3..80b4e6ef530f5986f5e148dd497318cdf22190cf 100644 (file)
@@ -330,8 +330,8 @@ namespace CecConfigGui
       SetControlEnabled(cbActivateSource, val);
       SetControlEnabled(cbPowerOffScreensaver, val);
       SetControlEnabled(cbPowerOffOnStandby, val);
-      SetControlEnabled(cbWakeDevices, false); // TODO not implemented yet
-      SetControlEnabled(cbPowerOffDevices, false); // TODO not implemented yet
+      SetControlEnabled(cbWakeDevices, val);
+      SetControlEnabled(cbPowerOffDevices, val);
       SetControlEnabled(cbVendorOverride, val);
       SetControlEnabled(cbVendorId, val && cbVendorOverride.Checked);
       SetControlEnabled(bClose, val);
@@ -512,6 +512,8 @@ namespace CecConfigGui
       Config.ActivateSource = cbActivateSource.Checked;
       Config.PowerOffScreensaver = cbPowerOffScreensaver.Checked;
       Config.PowerOffOnStandby = cbPowerOffOnStandby.Checked;
+      Config.WakeDevices = WakeDevices;
+      Config.PowerOffDevices = PowerOffDevices;
 
       if (!Lib.CanPersistConfiguration())
       {
@@ -565,18 +567,18 @@ namespace CecConfigGui
               output.AppendLine("<!-- the following lines are only supported by v1.5.0+ clients -->");
               output.AppendLine("<setting id=\"physical_address\" value=\"" + string.Format("{0,4:X}", Config.PhysicalAddress) + "\" />");
               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) + "\" />");
+              output.AppendLine("<setting id=\"tv_vendor\" value=\"" + string.Format("{0,6:X}", (int)Config.TvVendor).Trim() + "\" />");
 
               output.Append("<setting id=\"wake_devices\" value=\"");
               foreach (CecLogicalAddress addr in Config.WakeDevices.Addresses)
-                if (addr != CecLogicalAddress.Unregistered)
-                  output.Append(" " + addr);
+                if (addr != CecLogicalAddress.Unknown)
+                  output.Append(" " + (int)addr);
               output.AppendLine("\" />");
 
               output.Append("<setting id=\"standby_devices\" value=\"");
               foreach (CecLogicalAddress addr in Config.PowerOffDevices.Addresses)
-                if (addr != CecLogicalAddress.Unregistered)
-                  output.Append(" " + addr);
+                if (addr != CecLogicalAddress.Unknown)
+                  output.Append(" " + (int)addr);
               output.AppendLine("\" />");
 
               output.AppendLine("</settings>");
@@ -722,7 +724,7 @@ namespace CecConfigGui
       List<string> deviceList = new List<string>();
       foreach (CecLogicalAddress activeDevice in activeDevices.Addresses)
       {
-        if (activeDevice != CecLogicalAddress.Unregistered)
+        if (activeDevice != CecLogicalAddress.Unknown)
           deviceList.Add(string.Format("{0,1:X} : {1}", (int)activeDevice, Lib.ToString(activeDevice)));
       }
       deviceList.Add(string.Format("{0,1:X} : {1}", (int)CecLogicalAddress.Broadcast, Lib.ToString(CecLogicalAddress.Broadcast)));
@@ -765,7 +767,12 @@ namespace CecConfigGui
         return retval;
       }
 
-      switch (this.cbCommandDestination.Text.Substring(0, 1).ToLower())
+      return GetLogicalAddressFromString(this.cbCommandDestination.Text);
+    }
+
+    private CecLogicalAddress GetLogicalAddressFromString(string name)
+    {
+      switch (name.Substring(0, 1).ToLower())
       {
         case "0":
           return CecLogicalAddress.Tv;
@@ -1003,6 +1010,11 @@ namespace CecConfigGui
       SetCheckboxChecked(cbPowerOffScreensaver, Config.PowerOffScreensaver);
       SetCheckboxChecked(cbPowerOffOnStandby, Config.PowerOffOnStandby);
       UpdateSelectedDevice();
+
+      for (int iPtr = 0; iPtr < 15; iPtr++)
+        SetCheckboxItemChecked(cbWakeDevices, iPtr, Config.WakeDevices.IsSet((CecLogicalAddress)iPtr));
+      for (int iPtr = 0; iPtr < 15; iPtr++)
+        SetCheckboxItemChecked(cbPowerOffDevices, iPtr, Config.PowerOffDevices.IsSet((CecLogicalAddress)iPtr));
       return 1;
     }
 
@@ -1019,7 +1031,11 @@ namespace CecConfigGui
 
     public int ReceiveLogMessage(CecLogMessage message)
     {
-      AddLogMessage(message);
+      try
+      {
+        AddLogMessage(message);
+      }
+      catch (Exception) { }
       return 1;
     }
     #endregion
@@ -1101,6 +1117,32 @@ namespace CecConfigGui
     private string Log = string.Empty;
     private DeviceInformation UpdatingInfoPanel = null;
     private bool DeviceChangeWarningDisplayed = false;
+    public CecLogicalAddresses WakeDevices
+    {
+      get
+      {
+        CecLogicalAddresses addr = new CecLogicalAddresses();
+        foreach (object item in this.cbWakeDevices.CheckedItems)
+        {
+          string c = item as string;
+          addr.Set(GetLogicalAddressFromString(c));
+        }
+        return addr;
+      }
+    }
+    public CecLogicalAddresses PowerOffDevices
+    {
+      get
+      {
+        CecLogicalAddresses addr = new CecLogicalAddresses();
+        foreach (object item in this.cbPowerOffDevices.CheckedItems)
+        {
+          string c = item as string;
+          addr.Set(GetLogicalAddressFromString(c));
+        }
+        return addr;
+      }
+    }
     #endregion
   }