# HG changeset patch
# User StephaneLenclud
# Date 1469294576 -7200
# Node ID 96f8b4dc430063bddf52886b5fcba3f99bf39a55
# Parent  83dd86e7344875b8509f76862ed48290014ba4e7
Adding Events tab.

diff -r 83dd86e73448 -r 96f8b4dc4300 Server/FormEditAction.Designer.cs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/FormEditAction.Designer.cs	Sat Jul 23 19:22:56 2016 +0200
@@ -0,0 +1,104 @@
+namespace SharpDisplayManager
+{
+    partial class FormEditAction
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.comboBoxActionType = new System.Windows.Forms.ComboBox();
+            this.labelActionType = new System.Windows.Forms.Label();
+            this.buttonOk = new System.Windows.Forms.Button();
+            this.buttonCancel = new System.Windows.Forms.Button();
+            this.SuspendLayout();
+            // 
+            // comboBoxActionType
+            // 
+            this.comboBoxActionType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.comboBoxActionType.FormattingEnabled = true;
+            this.comboBoxActionType.Location = new System.Drawing.Point(55, 12);
+            this.comboBoxActionType.Name = "comboBoxActionType";
+            this.comboBoxActionType.Size = new System.Drawing.Size(333, 21);
+            this.comboBoxActionType.TabIndex = 18;
+            // 
+            // labelActionType
+            // 
+            this.labelActionType.AutoSize = true;
+            this.labelActionType.Location = new System.Drawing.Point(12, 15);
+            this.labelActionType.Name = "labelActionType";
+            this.labelActionType.Size = new System.Drawing.Size(37, 13);
+            this.labelActionType.TabIndex = 20;
+            this.labelActionType.Text = "Type :";
+            // 
+            // buttonOk
+            // 
+            this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
+            this.buttonOk.Location = new System.Drawing.Point(12, 55);
+            this.buttonOk.Name = "buttonOk";
+            this.buttonOk.Size = new System.Drawing.Size(75, 23);
+            this.buttonOk.TabIndex = 21;
+            this.buttonOk.Text = "Ok";
+            this.buttonOk.UseVisualStyleBackColor = true;
+            this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
+            // 
+            // buttonCancel
+            // 
+            this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+            this.buttonCancel.Location = new System.Drawing.Point(93, 55);
+            this.buttonCancel.Name = "buttonCancel";
+            this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+            this.buttonCancel.TabIndex = 22;
+            this.buttonCancel.Text = "Cancel";
+            this.buttonCancel.UseVisualStyleBackColor = true;
+            // 
+            // FormEditAction
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(400, 86);
+            this.Controls.Add(this.buttonCancel);
+            this.Controls.Add(this.buttonOk);
+            this.Controls.Add(this.labelActionType);
+            this.Controls.Add(this.comboBoxActionType);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
+            this.MaximizeBox = false;
+            this.MinimizeBox = false;
+            this.Name = "FormEditAction";
+            this.Text = "Edit action";
+            this.Load += new System.EventHandler(this.FormEditAction_Load);
+            this.Validating += new System.ComponentModel.CancelEventHandler(this.FormEditAction_Validating);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.ComboBox comboBoxActionType;
+        private System.Windows.Forms.Label labelActionType;
+        private System.Windows.Forms.Button buttonOk;
+        private System.Windows.Forms.Button buttonCancel;
+    }
+}
\ No newline at end of file
diff -r 83dd86e73448 -r 96f8b4dc4300 Server/FormEditAction.cs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/FormEditAction.cs	Sat Jul 23 19:22:56 2016 +0200
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using SharpLib.Ear;
+
+namespace SharpDisplayManager
+{
+    public partial class FormEditAction : Form
+    {
+        public SharpLib.Ear.Action Action = null;
+
+        public FormEditAction()
+        {
+            InitializeComponent();
+        }
+
+        private void FormEditAction_Load(object sender, EventArgs e)
+        {
+            //Populate registered actions
+            foreach (string key in EventActionManager.Current.ActionTypes.Keys)
+            {
+                Type t = EventActionManager.Current.ActionTypes[key];
+                comboBoxActionType.Items.Add(t);                
+            }
+
+            comboBoxActionType.SelectedIndex = 0;
+        }
+
+        private void buttonOk_Click(object sender, EventArgs e)
+        {
+            Action = (SharpLib.Ear.Action)Activator.CreateInstance((Type)comboBoxActionType.SelectedItem);
+        }
+
+        private void FormEditAction_Validating(object sender, CancelEventArgs e)
+        {
+
+        }
+    }
+}
diff -r 83dd86e73448 -r 96f8b4dc4300 Server/FormEditAction.resx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/FormEditAction.resx	Sat Jul 23 19:22:56 2016 +0200
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>
\ No newline at end of file
diff -r 83dd86e73448 -r 96f8b4dc4300 Server/MainForm.Designer.cs
--- a/Server/MainForm.Designer.cs	Sat Jul 23 16:00:04 2016 +0200
+++ b/Server/MainForm.Designer.cs	Sat Jul 23 19:22:56 2016 +0200
@@ -112,6 +112,10 @@
             this.checkBoxCecEnabled = new System.Windows.Forms.CheckBox();
             this.labelHdmiPort = new System.Windows.Forms.Label();
             this.comboBoxHdmiPort = new System.Windows.Forms.ComboBox();
+            this.tabPageEvent = new System.Windows.Forms.TabPage();
+            this.buttonDeleteAction = new System.Windows.Forms.Button();
+            this.buttonAddAction = new System.Windows.Forms.Button();
+            this.iTreeViewEvents = new System.Windows.Forms.TreeView();
             this.tabPageApp = new System.Windows.Forms.TabPage();
             this.checkBoxStartMinimized = new System.Windows.Forms.CheckBox();
             this.checkBoxMinimizeToTray = new System.Windows.Forms.CheckBox();
@@ -138,6 +142,7 @@
             ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGreenStart)).BeginInit();
             this.tabPageCec.SuspendLayout();
             this.groupBoxCecLogOptions.SuspendLayout();
+            this.tabPageEvent.SuspendLayout();
             this.tabPageApp.SuspendLayout();
             this.tabPageLogs.SuspendLayout();
             this.SuspendLayout();
@@ -566,6 +571,7 @@
             this.tabControl.Controls.Add(this.tabPageAudio);
             this.tabControl.Controls.Add(this.tabPageInput);
             this.tabControl.Controls.Add(this.tabPageCec);
+            this.tabControl.Controls.Add(this.tabPageEvent);
             this.tabControl.Controls.Add(this.tabPageApp);
             this.tabControl.Controls.Add(this.tabPageLogs);
             this.tabControl.Location = new System.Drawing.Point(12, 125);
@@ -1000,6 +1006,48 @@
             this.comboBoxHdmiPort.TabIndex = 19;
             this.comboBoxHdmiPort.SelectedIndexChanged += new System.EventHandler(this.comboBoxHdmiPort_SelectedIndexChanged);
             // 
+            // tabPageEvent
+            // 
+            this.tabPageEvent.Controls.Add(this.buttonDeleteAction);
+            this.tabPageEvent.Controls.Add(this.buttonAddAction);
+            this.tabPageEvent.Controls.Add(this.iTreeViewEvents);
+            this.tabPageEvent.Location = new System.Drawing.Point(4, 22);
+            this.tabPageEvent.Name = "tabPageEvent";
+            this.tabPageEvent.Padding = new System.Windows.Forms.Padding(3);
+            this.tabPageEvent.Size = new System.Drawing.Size(752, 385);
+            this.tabPageEvent.TabIndex = 9;
+            this.tabPageEvent.Text = "Events";
+            this.tabPageEvent.UseVisualStyleBackColor = true;
+            // 
+            // buttonDeleteAction
+            // 
+            this.buttonDeleteAction.Location = new System.Drawing.Point(6, 35);
+            this.buttonDeleteAction.Name = "buttonDeleteAction";
+            this.buttonDeleteAction.Size = new System.Drawing.Size(96, 23);
+            this.buttonDeleteAction.TabIndex = 21;
+            this.buttonDeleteAction.Text = "Delete Action";
+            this.buttonDeleteAction.UseVisualStyleBackColor = true;
+            // 
+            // buttonAddAction
+            // 
+            this.buttonAddAction.Location = new System.Drawing.Point(6, 6);
+            this.buttonAddAction.Name = "buttonAddAction";
+            this.buttonAddAction.Size = new System.Drawing.Size(96, 23);
+            this.buttonAddAction.TabIndex = 20;
+            this.buttonAddAction.Text = "Add Action";
+            this.buttonAddAction.UseVisualStyleBackColor = true;
+            this.buttonAddAction.Click += new System.EventHandler(this.buttonAddAction_Click);
+            // 
+            // iTreeViewEvents
+            // 
+            this.iTreeViewEvents.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.iTreeViewEvents.Location = new System.Drawing.Point(111, 3);
+            this.iTreeViewEvents.Name = "iTreeViewEvents";
+            this.iTreeViewEvents.Size = new System.Drawing.Size(638, 376);
+            this.iTreeViewEvents.TabIndex = 1;
+            // 
             // tabPageApp
             // 
             this.tabPageApp.Controls.Add(this.checkBoxStartMinimized);
@@ -1163,6 +1211,7 @@
             this.tabPageCec.PerformLayout();
             this.groupBoxCecLogOptions.ResumeLayout(false);
             this.groupBoxCecLogOptions.PerformLayout();
+            this.tabPageEvent.ResumeLayout(false);
             this.tabPageApp.ResumeLayout(false);
             this.tabPageApp.PerformLayout();
             this.tabPageLogs.ResumeLayout(false);
@@ -1258,6 +1307,10 @@
         private System.Windows.Forms.CheckBox checkBoxCecLogNotice;
         private System.Windows.Forms.CheckBox checkBoxCecLogTraffic;
         private System.Windows.Forms.CheckBox checkBoxCecLogNoPoll;
+        private System.Windows.Forms.TabPage tabPageEvent;
+        private System.Windows.Forms.TreeView iTreeViewEvents;
+        private System.Windows.Forms.Button buttonDeleteAction;
+        private System.Windows.Forms.Button buttonAddAction;
     }
 }
 
diff -r 83dd86e73448 -r 96f8b4dc4300 Server/MainForm.cs
--- a/Server/MainForm.cs	Sat Jul 23 16:00:04 2016 +0200
+++ b/Server/MainForm.cs	Sat Jul 23 19:22:56 2016 +0200
@@ -210,6 +210,8 @@
             OnWndProc += iCecManager.OnWndProc;
             ResetCec();
 
+            //Setup Events
+            SetupEvents();
 
             //Setup notification icon
             SetupTrayIcon();
@@ -285,6 +287,30 @@
 
 		}
 
+        /// <summary>
+        /// 
+        /// </summary>
+        private void SetupEvents()
+        {
+            //Reset our tree
+            iTreeViewEvents.Nodes.Clear();
+            //Populate registered events
+            foreach (string key in EventActionManager.Current.Events.Keys)
+            {
+                Event e = EventActionManager.Current.Events[key];
+                TreeNode eventNode = iTreeViewEvents.Nodes.Add(key,e.Name);
+                eventNode.Tag = e;
+                eventNode.Nodes.Add(key + ".Description", e.Description);
+                TreeNode actionsNodes = eventNode.Nodes.Add(key + ".Actions", "Actions");
+
+                foreach (SharpLib.Ear.Action a in e.Actions)
+                {
+                    actionsNodes.Nodes.Add(a.Name);
+                }
+            }
+
+        }
+
 		/// <summary>
 		/// Called when our display is closed.
 		/// </summary>
@@ -2625,5 +2651,23 @@
         {
             SetupCecLogLevel();
         }
+
+        private void buttonAddAction_Click(object sender, EventArgs e)
+        {
+            Event ear = (Event)iTreeViewEvents.SelectedNode.Tag;
+            if (ear == null)
+            {
+                //Must select event node
+                return;
+            }
+
+            FormEditAction ea = new FormEditAction();
+            DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(ea);
+            if (res == DialogResult.OK)
+            {
+                ear.Actions.Add(ea.Action);
+                SetupEvents();
+            }
+        }
     }
 }
diff -r 83dd86e73448 -r 96f8b4dc4300 Server/MainForm.resx
--- a/Server/MainForm.resx	Sat Jul 23 16:00:04 2016 +0200
+++ b/Server/MainForm.resx	Sat Jul 23 19:22:56 2016 +0200
@@ -185,9 +185,6 @@
         WSC3/b/CbwiR/gNzbuWksIMBOAAAAABJRU5ErkJggg==
 </value>
   </data>
-  <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>315, 17</value>
-  </metadata>
   <metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>405, 17</value>
   </metadata>
diff -r 83dd86e73448 -r 96f8b4dc4300 Server/SharpDisplayManager.csproj
--- a/Server/SharpDisplayManager.csproj	Sat Jul 23 16:00:04 2016 +0200
+++ b/Server/SharpDisplayManager.csproj	Sat Jul 23 19:22:56 2016 +0200
@@ -157,6 +157,12 @@
     <Compile Include="CecClient.cs" />
     <Compile Include="ConsumerElectronicControl.cs" />
     <Compile Include="ClientData.cs" />
+    <Compile Include="FormEditAction.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="FormEditAction.Designer.cs">
+      <DependentUpon>FormEditAction.cs</DependentUpon>
+    </Compile>
     <Compile Include="FxControl.cs">
       <SubType>UserControl</SubType>
     </Compile>
@@ -193,6 +199,9 @@
     <Compile Include="Win32API.cs" />
     <Compile Include="WindowsHook.cs" />
     <Compile Include="WndProcRetHook.cs" />
+    <EmbeddedResource Include="FormEditAction.resx">
+      <DependentUpon>FormEditAction.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="FxControl.resx">
       <DependentUpon>FxControl.cs</DependentUpon>
     </EmbeddedResource>
diff -r 83dd86e73448 -r 96f8b4dc4300 SharpLibEar/Action.cs
--- a/SharpLibEar/Action.cs	Sat Jul 23 16:00:04 2016 +0200
+++ b/SharpLibEar/Action.cs	Sat Jul 23 19:22:56 2016 +0200
@@ -12,6 +12,12 @@
     {
         public abstract void Execute();
 
+        public string Name {
+            //Get the name of this object action attribute
+            get { return Utils.Reflection.GetAttribute<AttributeAction>(GetType()).Name; }
+            private set { }
+        }
+
         public int CompareTo(object obj)
         {
             //Sort by action name
diff -r 83dd86e73448 -r 96f8b4dc4300 SharpLibEar/EventActionManager.cs
--- a/SharpLibEar/EventActionManager.cs	Sat Jul 23 16:00:04 2016 +0200
+++ b/SharpLibEar/EventActionManager.cs	Sat Jul 23 19:22:56 2016 +0200
@@ -14,7 +14,7 @@
     {
         public static EventActionManager Current = null;
         public IDictionary<string, Type> ActionTypes;
-        private IDictionary<string, Event> Events;
+        public readonly IDictionary<string, Event> Events;
 
         public EventActionManager()
         {
diff -r 83dd86e73448 -r 96f8b4dc4300 SharpLibEar/EventMonitorPowerOff.cs
--- a/SharpLibEar/EventMonitorPowerOff.cs	Sat Jul 23 16:00:04 2016 +0200
+++ b/SharpLibEar/EventMonitorPowerOff.cs	Sat Jul 23 19:22:56 2016 +0200
@@ -11,7 +11,7 @@
         public EventMonitorPowerOff()
         {
             Name = "Monitor Power Off";
-            Description = "";
+            Description = "Windows is powering off your monitor.";
         }
     }
 
diff -r 83dd86e73448 -r 96f8b4dc4300 SharpLibEar/EventMonitorPowerOn.cs
--- a/SharpLibEar/EventMonitorPowerOn.cs	Sat Jul 23 16:00:04 2016 +0200
+++ b/SharpLibEar/EventMonitorPowerOn.cs	Sat Jul 23 19:22:56 2016 +0200
@@ -11,7 +11,7 @@
         public EventMonitorPowerOn()
         {
             Name = "Monitor Power On";
-            Description = "";
+            Description = "Windows is powering on your monitor.";
         }
 
     }