# HG changeset patch # User StephaneLenclud # Date 1471255886 -7200 # Node ID 2b9541e54f7d97664a02601ec4a86517d0306249 # Parent 5a739e2e52556dd0aff4369b3ae0eded06458b2f Adding Harmony tab. diff -r 5a739e2e5255 -r 2b9541e54f7d Server/App.config --- a/Server/App.config Sat Aug 13 23:26:54 2016 +0200 +++ b/Server/App.config Mon Aug 15 12:11:26 2016 +0200 @@ -40,6 +40,12 @@ True + + False + + + HarmonyHub + diff -r 5a739e2e5255 -r 2b9541e54f7d Server/FormMain.Designer.cs --- a/Server/FormMain.Designer.cs Sat Aug 13 23:26:54 2016 +0200 +++ b/Server/FormMain.Designer.cs Mon Aug 15 12:11:26 2016 +0200 @@ -109,6 +109,16 @@ this.checkBoxCecEnabled = new System.Windows.Forms.CheckBox(); this.labelHdmiPort = new System.Windows.Forms.Label(); this.comboBoxHdmiPort = new System.Windows.Forms.ComboBox(); + this.tabPageHarmony = new System.Windows.Forms.TabPage(); + this.iCheckBoxHarmonyEnabled = new System.Windows.Forms.CheckBox(); + this.iTreeViewHarmony = new System.Windows.Forms.TreeView(); + this.iButtonHarmonyConnect = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.iTextBoxLogitechPassword = new System.Windows.Forms.TextBox(); + this.labelLogitechUserName = new System.Windows.Forms.Label(); + this.iTextBoxLogitechUserName = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.iTextBoxHarmonyHubAddress = new System.Windows.Forms.TextBox(); this.tabPageEvent = new System.Windows.Forms.TabPage(); this.buttonEventEdit = new System.Windows.Forms.Button(); this.buttonEventDelete = new System.Windows.Forms.Button(); @@ -147,6 +157,7 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGreenStart)).BeginInit(); this.tabPageCec.SuspendLayout(); this.groupBoxCecLogOptions.SuspendLayout(); + this.tabPageHarmony.SuspendLayout(); this.tabPageEvent.SuspendLayout(); this.tabPageApp.SuspendLayout(); this.tabPageLogs.SuspendLayout(); @@ -576,6 +587,7 @@ this.tabControl.Controls.Add(this.tabPageAudio); this.tabControl.Controls.Add(this.tabPageInput); this.tabControl.Controls.Add(this.tabPageCec); + this.tabControl.Controls.Add(this.tabPageHarmony); this.tabControl.Controls.Add(this.tabPageEvent); this.tabControl.Controls.Add(this.tabPageApp); this.tabControl.Controls.Add(this.tabPageLogs); @@ -975,6 +987,113 @@ this.comboBoxHdmiPort.TabIndex = 19; this.comboBoxHdmiPort.SelectedIndexChanged += new System.EventHandler(this.comboBoxHdmiPort_SelectedIndexChanged); // + // tabPageHarmony + // + this.tabPageHarmony.Controls.Add(this.iCheckBoxHarmonyEnabled); + this.tabPageHarmony.Controls.Add(this.iTreeViewHarmony); + this.tabPageHarmony.Controls.Add(this.iButtonHarmonyConnect); + this.tabPageHarmony.Controls.Add(this.label2); + this.tabPageHarmony.Controls.Add(this.iTextBoxLogitechPassword); + this.tabPageHarmony.Controls.Add(this.labelLogitechUserName); + this.tabPageHarmony.Controls.Add(this.iTextBoxLogitechUserName); + this.tabPageHarmony.Controls.Add(this.label1); + this.tabPageHarmony.Controls.Add(this.iTextBoxHarmonyHubAddress); + this.tabPageHarmony.Location = new System.Drawing.Point(4, 22); + this.tabPageHarmony.Name = "tabPageHarmony"; + this.tabPageHarmony.Padding = new System.Windows.Forms.Padding(3); + this.tabPageHarmony.Size = new System.Drawing.Size(752, 385); + this.tabPageHarmony.TabIndex = 10; + this.tabPageHarmony.Text = "Harmony"; + this.tabPageHarmony.UseVisualStyleBackColor = true; + // + // iCheckBoxHarmonyEnabled + // + this.iCheckBoxHarmonyEnabled.AutoSize = true; + this.iCheckBoxHarmonyEnabled.Location = new System.Drawing.Point(6, 6); + this.iCheckBoxHarmonyEnabled.Name = "iCheckBoxHarmonyEnabled"; + this.iCheckBoxHarmonyEnabled.Size = new System.Drawing.Size(104, 17); + this.iCheckBoxHarmonyEnabled.TabIndex = 22; + this.iCheckBoxHarmonyEnabled.Text = "Enable Harmony"; + this.iCheckBoxHarmonyEnabled.UseVisualStyleBackColor = true; + this.iCheckBoxHarmonyEnabled.CheckedChanged += new System.EventHandler(this.iCheckBoxHarmonyEnabled_CheckedChanged); + // + // iTreeViewHarmony + // + this.iTreeViewHarmony.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.iTreeViewHarmony.Location = new System.Drawing.Point(84, 49); + this.iTreeViewHarmony.Name = "iTreeViewHarmony"; + this.iTreeViewHarmony.Size = new System.Drawing.Size(662, 330); + this.iTreeViewHarmony.TabIndex = 15; + this.iTreeViewHarmony.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.iTreeViewHarmony_NodeMouseDoubleClick); + // + // iButtonHarmonyConnect + // + this.iButtonHarmonyConnect.Location = new System.Drawing.Point(3, 49); + this.iButtonHarmonyConnect.Name = "iButtonHarmonyConnect"; + this.iButtonHarmonyConnect.Size = new System.Drawing.Size(75, 23); + this.iButtonHarmonyConnect.TabIndex = 14; + this.iButtonHarmonyConnect.Text = "Connect"; + this.iButtonHarmonyConnect.UseVisualStyleBackColor = true; + this.iButtonHarmonyConnect.Click += new System.EventHandler(this.iButtonHarmonyConnect_Click); + // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(597, 7); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(99, 13); + this.label2.TabIndex = 13; + this.label2.Text = "Logitech password:"; + // + // iTextBoxLogitechPassword + // + this.iTextBoxLogitechPassword.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.iTextBoxLogitechPassword.Location = new System.Drawing.Point(600, 23); + this.iTextBoxLogitechPassword.Name = "iTextBoxLogitechPassword"; + this.iTextBoxLogitechPassword.PasswordChar = '*'; + this.iTextBoxLogitechPassword.Size = new System.Drawing.Size(134, 20); + this.iTextBoxLogitechPassword.TabIndex = 12; + // + // labelLogitechUserName + // + this.labelLogitechUserName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.labelLogitechUserName.AutoSize = true; + this.labelLogitechUserName.Location = new System.Drawing.Point(433, 7); + this.labelLogitechUserName.Name = "labelLogitechUserName"; + this.labelLogitechUserName.Size = new System.Drawing.Size(141, 13); + this.labelLogitechUserName.TabIndex = 11; + this.labelLogitechUserName.Text = "Logitech user name / e-mail:"; + // + // iTextBoxLogitechUserName + // + this.iTextBoxLogitechUserName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.iTextBoxLogitechUserName.Location = new System.Drawing.Point(436, 23); + this.iTextBoxLogitechUserName.Name = "iTextBoxLogitechUserName"; + this.iTextBoxLogitechUserName.Size = new System.Drawing.Size(134, 20); + this.iTextBoxLogitechUserName.TabIndex = 10; + // + // label1 + // + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(279, 7); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(116, 13); + this.label1.TabIndex = 9; + this.label1.Text = "Harmony Hub Address:"; + // + // iTextBoxHarmonyHubAddress + // + this.iTextBoxHarmonyHubAddress.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.iTextBoxHarmonyHubAddress.Location = new System.Drawing.Point(282, 23); + this.iTextBoxHarmonyHubAddress.Name = "iTextBoxHarmonyHubAddress"; + this.iTextBoxHarmonyHubAddress.Size = new System.Drawing.Size(100, 20); + this.iTextBoxHarmonyHubAddress.TabIndex = 8; + this.iTextBoxHarmonyHubAddress.Text = "HarmonyHub"; + // // tabPageEvent // this.tabPageEvent.Controls.Add(this.buttonEventEdit); @@ -1281,6 +1400,8 @@ this.tabPageCec.PerformLayout(); this.groupBoxCecLogOptions.ResumeLayout(false); this.groupBoxCecLogOptions.PerformLayout(); + this.tabPageHarmony.ResumeLayout(false); + this.tabPageHarmony.PerformLayout(); this.tabPageEvent.ResumeLayout(false); this.tabPageApp.ResumeLayout(false); this.tabPageApp.PerformLayout(); @@ -1386,6 +1507,16 @@ private System.Windows.Forms.Button buttonEventDelete; private System.Windows.Forms.Button buttonEventAdd; private System.Windows.Forms.Button buttonEventEdit; + private System.Windows.Forms.TabPage tabPageHarmony; + private System.Windows.Forms.TreeView iTreeViewHarmony; + private System.Windows.Forms.Button iButtonHarmonyConnect; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox iTextBoxLogitechPassword; + private System.Windows.Forms.Label labelLogitechUserName; + private System.Windows.Forms.TextBox iTextBoxLogitechUserName; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox iTextBoxHarmonyHubAddress; + private System.Windows.Forms.CheckBox iCheckBoxHarmonyEnabled; } } diff -r 5a739e2e5255 -r 2b9541e54f7d Server/FormMain.Hid.cs --- a/Server/FormMain.Hid.cs Sat Aug 13 23:26:54 2016 +0200 +++ b/Server/FormMain.Hid.cs Mon Aug 15 12:11:26 2016 +0200 @@ -45,31 +45,31 @@ int i = 0; rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.WindowsMediaCenterRemoteControl; rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.WindowsMediaCenter.WindowsMediaCenterRemoteControl; - rid[i].dwFlags = Const.RIDEV_INPUTSINK; + rid[i].dwFlags = RawInputDeviceFlags.RIDEV_INPUTSINK; rid[i].hwndTarget = Handle; i++; rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer; rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.ConsumerControl; - rid[i].dwFlags = Const.RIDEV_INPUTSINK; + rid[i].dwFlags = RawInputDeviceFlags.RIDEV_INPUTSINK; rid[i].hwndTarget = Handle; i++; rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer; rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.Selection; - rid[i].dwFlags = Const.RIDEV_INPUTSINK; + rid[i].dwFlags = RawInputDeviceFlags.RIDEV_INPUTSINK; rid[i].hwndTarget = Handle; i++; rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.SystemControl; - rid[i].dwFlags = Const.RIDEV_INPUTSINK; + rid[i].dwFlags = RawInputDeviceFlags.RIDEV_INPUTSINK; rid[i].hwndTarget = Handle; i++; rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.GamePad; - rid[i].dwFlags = Const.RIDEV_INPUTSINK; + rid[i].dwFlags = RawInputDeviceFlags.RIDEV_INPUTSINK; rid[i].hwndTarget = Handle; //i++; diff -r 5a739e2e5255 -r 2b9541e54f7d Server/FormMain.cs --- a/Server/FormMain.cs Sat Aug 13 23:26:54 2016 +0200 +++ b/Server/FormMain.cs Mon Aug 15 12:11:26 2016 +0200 @@ -233,6 +233,9 @@ OnWndProc += iCecManager.OnWndProc; ResetCec(); + //Harmony + ResetHarmony(); + //Setup Events PopulateEventsTreeView(); @@ -1265,6 +1268,10 @@ comboBoxOpticalDrives.SelectedIndex = 0; } + //Harmony settings + iCheckBoxHarmonyEnabled.Checked = Properties.Settings.Default.HarmonyEnabled; + iTextBoxHarmonyHubAddress.Text = Properties.Settings.Default.HarmonyHubAddress; + //CEC settings checkBoxCecEnabled.Checked = Properties.Settings.Default.CecEnabled; comboBoxHdmiPort.SelectedIndex = Properties.Settings.Default.CecHdmiPort - 1; @@ -2693,6 +2700,27 @@ /// /// /// + private async void ResetHarmony() + { + // ConnectAsync already if we have an existing session cookie + if (Properties.Settings.Default.HarmonyEnabled && File.Exists("SessionToken")) + { + + iButtonHarmonyConnect.Enabled = false; + try + { + await ConnectHarmonyAsync(); + } + finally + { + iButtonHarmonyConnect.Enabled = true; + } + } + } + + /// + /// + /// private void SetupCecLogLevel() { //Setup log level @@ -3061,5 +3089,106 @@ //Make sure our event tree never looses focus ((TreeView) sender).Focus(); } + + private async void iButtonHarmonyConnect_Click(object sender, EventArgs e) + { + //Save hub address + Properties.Settings.Default.HarmonyHubAddress = iTextBoxHarmonyHubAddress.Text; + Properties.Settings.Default.Save(); + + iButtonHarmonyConnect.Enabled = false; + try + { + await ConnectHarmonyAsync(); + } + catch (Exception) + { + iButtonHarmonyConnect.Enabled = true; + } + + } + + + private async Task ConnectHarmonyAsync() + { + Console.WriteLine("Harmony: Connecting... "); + //First create our client and login + if (File.Exists("SessionToken")) + { + var sessionToken = File.ReadAllText("SessionToken"); + Console.WriteLine("Harmony: Reusing token: {0}", sessionToken); + Program.HarmonyClient = HarmonyHub.HarmonyClient.Create(iTextBoxHarmonyHubAddress.Text, sessionToken); + } + else + { + if (string.IsNullOrEmpty(iTextBoxLogitechPassword.Text)) + { + Console.WriteLine("Harmony: Credentials missing!"); + return; + } + + Console.WriteLine("Harmony: Authenticating with Logitech servers..."); + Program.HarmonyClient = await HarmonyHub.HarmonyClient.Create(iTextBoxHarmonyHubAddress.Text, iTextBoxLogitechUserName.Text, iTextBoxLogitechPassword.Text); + File.WriteAllText("SessionToken", Program.HarmonyClient.Token); + } + + Console.WriteLine("Harmony: Fetching Harmony Hub configuration..."); + + //Fetch our config + var harmonyConfig = await Program.HarmonyClient.GetConfigAsync(); + PopulateTreeViewHarmony(harmonyConfig); + + Console.WriteLine("Harmony: Ready"); + } + + /// + /// + /// + /// + private void PopulateTreeViewHarmony(HarmonyHub.Entities.Response.Config aConfig) + { + iTreeViewHarmony.Nodes.Clear(); + //Add our devices + foreach (HarmonyHub.Entities.Response.Device device in aConfig.Devices) + { + TreeNode deviceNode = iTreeViewHarmony.Nodes.Add(device.Id, $"{device.Label} ({device.DeviceTypeDisplayName}/{device.Model})"); + deviceNode.Tag = device; + + foreach (HarmonyHub.Entities.Response.ControlGroup cg in device.ControlGroups) + { + TreeNode cgNode = deviceNode.Nodes.Add(cg.Name); + cgNode.Tag = cg; + + foreach (HarmonyHub.Entities.Response.Function f in cg.Functions) + { + TreeNode fNode = cgNode.Nodes.Add(f.Name); + fNode.Tag = f; + } + } + } + + //treeViewConfig.ExpandAll(); + } + + private void iCheckBoxHarmonyEnabled_CheckedChanged(object sender, EventArgs e) + { + Properties.Settings.Default.HarmonyEnabled = iCheckBoxHarmonyEnabled.Checked; + Properties.Settings.Default.Save(); + } + + private async void iTreeViewHarmony_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + //Upon function node double click we execute it + var tag = e.Node.Tag as HarmonyHub.Entities.Response.Function; + if (tag != null && e.Node.Parent.Parent.Tag is HarmonyHub.Entities.Response.Device) + { + HarmonyHub.Entities.Response.Function f = tag; + HarmonyHub.Entities.Response.Device d = (HarmonyHub.Entities.Response.Device)e.Node.Parent.Parent.Tag; + + Console.WriteLine($"Harmony: Sending {f.Name} to {d.Label}..."); + + await Program.HarmonyClient.SendCommandAsync(d.Id, f.Name); + } + } } } diff -r 5a739e2e5255 -r 2b9541e54f7d Server/Program.cs --- a/Server/Program.cs Sat Aug 13 23:26:54 2016 +0200 +++ b/Server/Program.cs Mon Aug 15 12:11:26 2016 +0200 @@ -18,13 +18,10 @@ // using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; using System.Security.Principal; -using System.Diagnostics; -using System.Reflection; +using HarmonyHub; + namespace SharpDisplayManager { @@ -33,6 +30,9 @@ //WARNING: This is assuming we have a single instance of our program. //That is what we want but we should enforce it somehow. public static FormMain iFormMain; + + // + public static HarmonyClient HarmonyClient { get; set; } /// /// The main entry point for the application. /// diff -r 5a739e2e5255 -r 2b9541e54f7d Server/Properties/Settings.Designer.cs --- a/Server/Properties/Settings.Designer.cs Sat Aug 13 23:26:54 2016 +0200 +++ b/Server/Properties/Settings.Designer.cs Mon Aug 15 12:11:26 2016 +0200 @@ -164,5 +164,29 @@ this["Events"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool HarmonyEnabled { + get { + return ((bool)(this["HarmonyEnabled"])); + } + set { + this["HarmonyEnabled"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("HarmonyHub")] + public string HarmonyHubAddress { + get { + return ((string)(this["HarmonyHubAddress"])); + } + set { + this["HarmonyHubAddress"] = value; + } + } } } diff -r 5a739e2e5255 -r 2b9541e54f7d Server/Properties/Settings.settings --- a/Server/Properties/Settings.settings Sat Aug 13 23:26:54 2016 +0200 +++ b/Server/Properties/Settings.settings Mon Aug 15 12:11:26 2016 +0200 @@ -38,5 +38,11 @@ + + False + + + HarmonyHub + \ No newline at end of file diff -r 5a739e2e5255 -r 2b9541e54f7d Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Sat Aug 13 23:26:54 2016 +0200 +++ b/Server/SharpDisplayManager.csproj Mon Aug 15 12:11:26 2016 +0200 @@ -107,6 +107,14 @@ LocalIntranet + + ..\packages\Loamen.agsXMPP.1.3.1\lib\net45\agsXMPP.dll + True + + + ..\packages\SharpLibHarmony.0.2.1\lib\net451\HarmonyHub.dll + True + .\LibCecSharp.dll False @@ -125,7 +133,7 @@ True - ..\packages\SharpLibHid.1.3.1\lib\net20\SharpLibHid.dll + ..\packages\SharpLibHid.1.4.2\lib\net40\SharpLibHid.dll True @@ -133,8 +141,8 @@ True - False - ..\packages\SharpLibWin32.0.0.7\lib\net20\SharpLibWin32.dll + ..\packages\SharpLibWin32.0.0.9\lib\net20\SharpLibWin32.dll + True diff -r 5a739e2e5255 -r 2b9541e54f7d Server/packages.config --- a/Server/packages.config Sat Aug 13 23:26:54 2016 +0200 +++ b/Server/packages.config Mon Aug 15 12:11:26 2016 +0200 @@ -1,9 +1,11 @@  + - + + - + \ No newline at end of file