# HG changeset patch
# User StephaneLenclud
# Date 1469610455 -7200
# Node ID 0e8c6c2f4777b07930576a931a498f4f2099ecbe
# Parent 5770478e1fe3bc7f551e729da0bc35989421709b
Adding send and release CEC key actions.
Edit action ComboBox now sorted and selecting proper item.
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecActiveSource.cs
--- a/Server/Actions/ActionCecActiveSource.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/Actions/ActionCecActiveSource.cs Wed Jul 27 11:07:35 2016 +0200
@@ -11,16 +11,29 @@
{
[DataContract]
[AttributeAction(Id = "Cec.ActiveSource", Name = "CEC Active Source", Description = "Set this CEC device as active source.")]
- class ActionCecActiveSource : SharpLib.Ear.Action
+ class ActionCecActiveSource : ActionCecDeviceType
{
+ ///
+ /// Build a user readable string to describe this action.
+ ///
+ ///
+ public override string Brief()
+ {
+ return "CEC Active Source to " + DeviceType.ToString();
+ }
+
+ ///
+ /// Set the defined device type as active source.
+ ///
public override void Execute()
{
if (Cec.Client.Static == null)
{
Console.WriteLine("WARNING: No CEC client installed.");
+ return;
}
- Cec.Client.Static.Lib.SetActiveSource(CecDeviceType.PlaybackDevice);
+ Cec.Client.Static.Lib.SetActiveSource(DeviceType);
}
}
}
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecClose.cs
--- a/Server/Actions/ActionCecClose.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/Actions/ActionCecClose.cs Wed Jul 27 11:07:35 2016 +0200
@@ -18,6 +18,7 @@
if (Cec.Client.Static == null)
{
Console.WriteLine("WARNING: No CEC client installed.");
+ return;
}
Cec.Client.Static.Close();
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecDevice.cs
--- a/Server/Actions/ActionCecDevice.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/Actions/ActionCecDevice.cs Wed Jul 27 11:07:35 2016 +0200
@@ -10,6 +10,9 @@
namespace SharpDisplayManager
{
+ ///
+ /// Abstract CEC action using a device logical address.
+ ///
[DataContract]
public abstract class ActionCecDevice: SharpLib.Ear.Action
{
@@ -22,5 +25,22 @@
)
]
public CecLogicalAddress Device { get; set; }
+
+ ///
+ ///
+ ///
+ public string DeviceName {
+ get
+ {
+ if (Device == CecLogicalAddress.Broadcast)
+ {
+ //Because of duplicate value in enumeration
+ return "Broadcast";
+ }
+
+ return Device.ToString();
+ }
+ }
+
}
}
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecDevicePowerOn.cs
--- a/Server/Actions/ActionCecDevicePowerOn.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/Actions/ActionCecDevicePowerOn.cs Wed Jul 27 11:07:35 2016 +0200
@@ -20,13 +20,7 @@
///
public override string Brief()
{
- if (Device == CecLogicalAddress.Broadcast)
- {
- //Because of duplicated values it would display Unregistered
- return "CEC Power On Broadcast";
- }
-
- return "CEC Power On " + Device.ToString();
+ return "CEC Power On " + DeviceName;
}
///
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecDeviceStandby.cs
--- a/Server/Actions/ActionCecDeviceStandby.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/Actions/ActionCecDeviceStandby.cs Wed Jul 27 11:07:35 2016 +0200
@@ -15,18 +15,12 @@
public class ActionCecDeviceStandby : ActionCecDevice
{
///
- ///
+ /// Build a user readable string to describe this action.
///
///
public override string Brief()
{
- if (Device == CecLogicalAddress.Broadcast)
- {
- //Because of duplicated values it would display Unregistered
- return "CEC Standby Broadcast";
- }
-
- return "CEC Standby " + Device.ToString();
+ return "CEC Standby " + DeviceName;
}
///
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecDeviceType.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Actions/ActionCecDeviceType.cs Wed Jul 27 11:07:35 2016 +0200
@@ -0,0 +1,29 @@
+using CecSharp;
+using SharpLib.Ear;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SharpDisplayManager
+{
+ ///
+ /// Abstract CEC action using a device type.
+ ///
+ [DataContract]
+ public abstract class ActionCecDeviceType : SharpLib.Ear.Action
+ {
+ [DataMember]
+ [AttributeActionProperty
+ (
+ Id = "CEC.DeviceType",
+ Name = "Device Type",
+ Description = "The device type used by this action."
+ )
+ ]
+ public CecDeviceType DeviceType { get; set; }
+ }
+}
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecInactiveSource.cs
--- a/Server/Actions/ActionCecInactiveSource.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/Actions/ActionCecInactiveSource.cs Wed Jul 27 11:07:35 2016 +0200
@@ -18,6 +18,7 @@
if (Cec.Client.Static == null)
{
Console.WriteLine("WARNING: No CEC client installed.");
+ return;
}
Cec.Client.Static.Lib.SetInactiveView();
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecOpen.cs
--- a/Server/Actions/ActionCecOpen.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/Actions/ActionCecOpen.cs Wed Jul 27 11:07:35 2016 +0200
@@ -18,6 +18,7 @@
if (Cec.Client.Static == null)
{
Console.WriteLine("WARNING: No CEC client installed.");
+ return;
}
Cec.Client.Static.Open(1000);
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecPowerOnTv.cs
--- a/Server/Actions/ActionCecPowerOnTv.cs Tue Jul 26 15:30:46 2016 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-using CecSharp;
-using SharpLib.Ear;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SharpDisplayManager
-{
- [DataContract]
- [AttributeAction(Id = "Cec.PowerOnTv", Name = "CEC Power On TV", Description = "Power on TVs on your CEC HDMI network.")]
- class ActionCecPowerOnTv : SharpLib.Ear.Action
- {
- public override void Execute()
- {
- if (Cec.Client.Static == null)
- {
- Console.WriteLine("WARNING: No CEC client installed.");
- }
-
- Cec.Client.Static.Lib.PowerOnDevices(CecLogicalAddress.Tv);
- }
- }
-}
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecScan.cs
--- a/Server/Actions/ActionCecScan.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/Actions/ActionCecScan.cs Wed Jul 27 11:07:35 2016 +0200
@@ -19,6 +19,7 @@
if (Cec.Client.Static == null)
{
Console.WriteLine("WARNING: No CEC client installed.");
+ return;
}
Cec.Client.Static.Scan();
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecSendKeypressTvPowerOff.cs
--- a/Server/Actions/ActionCecSendKeypressTvPowerOff.cs Tue Jul 26 15:30:46 2016 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-
-using CecSharp;
-using SharpLib.Ear;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SharpDisplayManager
-{
- [DataContract]
- [AttributeAction(Id = "Cec.SendKepressTvPowerOff", Name = "CEC Send Keypress TV Power Off", Description = "Send Power Off keypress to your TV.")]
- class ActionCecSendKeypressTvPowerOff : SharpLib.Ear.Action
- {
- public override void Execute()
- {
- if (Cec.Client.Static == null)
- {
- Console.WriteLine("WARNING: No CEC client installed.");
- }
-
- Cec.Client.Static.Lib.SendKeypress(CecLogicalAddress.Tv,CecUserControlCode.PowerOffFunction,true);
- }
- }
-}
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecSendKeypressTvPowerOn.cs
--- a/Server/Actions/ActionCecSendKeypressTvPowerOn.cs Tue Jul 26 15:30:46 2016 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-
-using CecSharp;
-using SharpLib.Ear;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SharpDisplayManager
-{
- [DataContract]
- [AttributeAction(Id = "Cec.SendKepressTvPowerOn", Name = "CEC Send Keypress TV Power On", Description = "Send Power On keypress to your TV.")]
- class ActionCecSendKeypressTvPowerOn : SharpLib.Ear.Action
- {
- public override void Execute()
- {
- if (Cec.Client.Static == null)
- {
- Console.WriteLine("WARNING: No CEC client installed.");
- }
-
- Cec.Client.Static.Lib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.PowerOnFunction, true);
- }
- }
-}
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecStandbyTv.cs
--- a/Server/Actions/ActionCecStandbyTv.cs Tue Jul 26 15:30:46 2016 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-using CecSharp;
-using SharpLib.Ear;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SharpDisplayManager
-{
- [DataContract]
- [AttributeAction(Id = "Cec.StandbyTv", Name = "CEC Standby TV", Description = "Standby TVs on your CEC HDMI network.")]
- class ActionCecStandbyTv : SharpLib.Ear.Action
- {
- public override void Execute()
- {
- if (Cec.Client.Static == null)
- {
- Console.WriteLine("WARNING: No CEC client installed.");
- }
-
- Cec.Client.Static.Lib.StandbyDevices(CecLogicalAddress.Tv);
- }
- }
-}
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecUserControlPressed.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Actions/ActionCecUserControlPressed.cs Wed Jul 27 11:07:35 2016 +0200
@@ -0,0 +1,70 @@
+using CecSharp;
+using SharpLib.Ear;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SharpDisplayManager
+{
+ ///
+ /// Send a user key press event to the given CEC device.
+ ///
+ [DataContract]
+ [AttributeAction(Id = "Cec.UserControlPressed", Name = "CEC User Control Pressed", Description = "Send user control code to defined CEC device.")]
+ public class ActionCecUserControlPressed : ActionCecDevice
+ {
+
+ public ActionCecUserControlPressed()
+ {
+ Wait = true;
+ }
+
+ [DataMember]
+ [AttributeActionProperty(
+ Id = "Cec.UserControlPressed.Code",
+ Name = "Code",
+ Description = "The key code used by this action."
+ )]
+ public CecUserControlCode Code { get; set; }
+
+ [DataMember]
+ [AttributeActionProperty(
+ Id = "Cec.UserControlPressed.Wait",
+ Name = "Wait",
+ Description = "Wait for that command."
+ )]
+ public bool Wait { get; set; }
+
+ ///
+ ///
+ ///
+ ///
+ public override string Brief()
+ {
+ string brief = Name + ": " + Code.ToString() + " to " + DeviceName;
+ if (Wait)
+ {
+ brief += " (wait)";
+ }
+ return brief;
+ }
+
+ ///
+ ///
+ ///
+ public override void Execute()
+ {
+ if (Cec.Client.Static == null)
+ {
+ Console.WriteLine("WARNING: No CEC client installed.");
+ return;
+ }
+
+ Cec.Client.Static.Lib.SendKeypress(Device, Code, Wait);
+ }
+ }
+}
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/Actions/ActionCecUserControlReleased.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Actions/ActionCecUserControlReleased.cs Wed Jul 27 11:07:35 2016 +0200
@@ -0,0 +1,62 @@
+using CecSharp;
+using SharpLib.Ear;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SharpDisplayManager
+{
+ ///
+ /// Send a user key press event to the given CEC device.
+ ///
+ [DataContract]
+ [AttributeAction(Id = "Cec.UserControlReleased", Name = "CEC User Control Released", Description = "Send user control release opcode to a given CEC device.")]
+ public class ActionCecUserControlReleased : ActionCecDevice
+ {
+
+ public ActionCecUserControlReleased()
+ {
+ Wait = true;
+ }
+
+ [DataMember]
+ [AttributeActionProperty(
+ Id = "Cec.UserControlPressed.Wait",
+ Name = "Wait",
+ Description = "Wait for that command."
+ )]
+ public bool Wait { get; set; }
+
+ ///
+ ///
+ ///
+ ///
+ public override string Brief()
+ {
+ string brief = Name + " to " + DeviceName;
+ if (Wait)
+ {
+ brief += " (wait)";
+ }
+ return brief;
+ }
+
+ ///
+ ///
+ ///
+ public override void Execute()
+ {
+ if (Cec.Client.Static == null)
+ {
+ Console.WriteLine("WARNING: No CEC client installed.");
+ return;
+ }
+
+ Cec.Client.Static.Lib.SendKeyRelease(Device, Wait);
+ }
+ }
+}
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/FormEditAction.Designer.cs
--- a/Server/FormEditAction.Designer.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/FormEditAction.Designer.cs Wed Jul 27 11:07:35 2016 +0200
@@ -94,7 +94,7 @@
this.iTableLayoutPanel.RowCount = 2;
this.iTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.iTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
- this.iTableLayoutPanel.Size = new System.Drawing.Size(373, 16);
+ this.iTableLayoutPanel.Size = new System.Drawing.Size(375, 16);
this.iTableLayoutPanel.TabIndex = 23;
//
// FormEditAction
@@ -104,7 +104,7 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.CancelButton = this.buttonCancel;
- this.ClientSize = new System.Drawing.Size(400, 107);
+ this.ClientSize = new System.Drawing.Size(402, 107);
this.Controls.Add(this.iTableLayoutPanel);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOk);
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/FormEditAction.cs
--- a/Server/FormEditAction.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/FormEditAction.cs Wed Jul 27 11:07:35 2016 +0200
@@ -107,6 +107,11 @@
// Set enum value
aInfo.SetValue(aAction, enumValue);
}
+ else if (aInfo.PropertyType == typeof(bool))
+ {
+ CheckBox ctrl = (CheckBox)aControl;
+ aInfo.SetValue(aAction, ctrl.Checked);
+ }
}
///
@@ -119,7 +124,8 @@
if (aInfo.PropertyType == typeof(int))
{
//Integer properties are using numeric editor
- NumericUpDown ctrl = new NumericUpDown();
+ NumericUpDown ctrl = new NumericUpDown();
+ ctrl.AutoSize = true;
ctrl.Minimum = Int32.Parse(aAttribute.Minimum);
ctrl.Maximum = Int32.Parse(aAttribute.Maximum);
ctrl.Increment = Int32.Parse(aAttribute.Increment);
@@ -130,6 +136,8 @@
{
//Enum properties are using combo box
ComboBox ctrl = new ComboBox();
+ ctrl.AutoSize = true;
+ ctrl.Sorted = true;
ctrl.DropDownStyle = ComboBoxStyle.DropDownList;
//Data source is fine but it gives us duplicate entries for duplicated enum values
//ctrl.DataSource = Enum.GetValues(aInfo.PropertyType);
@@ -140,11 +148,22 @@
ctrl.Items.Add(name.ToString());
}
- //Select the first item
- ctrl.SelectedItem=ctrl.Items[0];
+ // Instantiate our enum
+ object enumValue = Activator.CreateInstance(aInfo.PropertyType);
+ enumValue = aInfo.GetValue(aAction);
+ //Set the current item
+ ctrl.SelectedItem = enumValue.ToString();
return ctrl;
}
+ else if (aInfo.PropertyType == typeof(bool))
+ {
+ CheckBox ctrl = new CheckBox();
+ ctrl.AutoSize = true;
+ ctrl.Text = aAttribute.Description;
+ ctrl.Checked = (bool)aInfo.GetValue(aAction);
+ return ctrl;
+ }
return null;
}
@@ -163,6 +182,10 @@
{
return true;
}
+ else if (aInfo.PropertyType == typeof(bool))
+ {
+ return true;
+ }
return false;
}
diff -r 5770478e1fe3 -r 0e8c6c2f4777 Server/SharpDisplayManager.csproj
--- a/Server/SharpDisplayManager.csproj Tue Jul 26 15:30:46 2016 +0200
+++ b/Server/SharpDisplayManager.csproj Wed Jul 27 11:07:35 2016 +0200
@@ -155,16 +155,15 @@
+
-
-
+
-
-
+
diff -r 5770478e1fe3 -r 0e8c6c2f4777 SharpLibUtils/TypeConverterJson.cs
--- a/SharpLibUtils/TypeConverterJson.cs Tue Jul 26 15:30:46 2016 +0200
+++ b/SharpLibUtils/TypeConverterJson.cs Wed Jul 27 11:07:35 2016 +0200
@@ -33,7 +33,7 @@
}
///
- ///
+ /// Internalize
///
///
///
@@ -44,22 +44,35 @@
string stringValue = value as string;
if (stringValue != null)
{
- //Load object form JSON string
- byte[] byteArray = Encoding.UTF8.GetBytes(stringValue);
- MemoryStream stream = new MemoryStream(byteArray);
- DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T), new DataContractJsonSerializerSettings()
- {
- UseSimpleDictionaryFormat = true
- });
- T settings = (T)ser.ReadObject(stream);
- return settings;
+ //try
+ //{
+ //Load object form JSON string
+ byte[] byteArray = Encoding.UTF8.GetBytes(stringValue);
+ MemoryStream stream = new MemoryStream(byteArray);
+ DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T),
+ new DataContractJsonSerializerSettings()
+ {
+ UseSimpleDictionaryFormat = true
+ });
+ T settings = (T)ser.ReadObject(stream);
+ return settings;
+ //}
+ //catch (Exception ex)
+ //{
+ //That's not helping with partial loading
+ // Console.WriteLine("WARNING: Internalize exception -" + ex.ToString() );
+ // return null;
+ //}
}
else
+ {
return base.ConvertFrom(context, culture, value);
+ }
+
}
///
- ///
+ /// Externalize
///
///
///