added ActivateSource action to cectray
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 13 Dec 2013 14:17:41 +0000 (15:17 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 13 Dec 2013 14:45:05 +0000 (15:45 +0100)
src/LibCecTray/LibCECTray.csproj
src/LibCecTray/controller/Actions.cs
src/LibCecTray/controller/actions/ActivateSource.cs [new file with mode: 0644]
src/LibCecTray/ui/CECTray.cs
src/LibCecTray/ui/DeviceInformation.cs

index bfa1d9f81533752c5af000eab71e1b47979775bd..86cc6de3475dce9fadadb5d07b561b19b96bda2e 100644 (file)
@@ -78,6 +78,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="controller\Actions.cs" />
+    <Compile Include="controller\actions\ActivateSource.cs" />
     <Compile Include="controller\actions\GetCurrentPhysicalAddress.cs" />
     <Compile Include="controller\actions\UpdateConfiguration.cs" />
     <Compile Include="controller\actions\ConnectToDevice.cs" />
index 2970ede803824a9a3af27b3acb6380e41634e719..355f94ee4c5b6fa2bf8d5604482636d252028c10 100644 (file)
@@ -208,7 +208,7 @@ namespace LibCECTray.controller
     /// Activate the source at the given logical address. 
     /// </summary>
     /// <param name="address">The logical address of the device to activate</param>
-    public void ActivateSource(CecLogicalAddress address)
+    public void SetStreamPath(CecLogicalAddress address)
     {
       if (SuppressUpdates || _activeProcess != null) return;
 
@@ -218,6 +218,16 @@ namespace LibCECTray.controller
       (new Thread(_activeProcess.Run)).Start();
     }
 
+    public void ActivateSource()
+    {
+      if (SuppressUpdates || _activeProcess != null) return;
+
+      _controller.SetControlsEnabled(false);
+      _activeProcess = new ActivateSource(_controller.Lib);
+      _activeProcess.EventHandler += ProcessEventHandler;
+      (new Thread(_activeProcess.Run)).Start();
+    }
+
     /// <summary>
     /// Send a standby command to the device at the given logical address
     /// </summary>
diff --git a/src/LibCecTray/controller/actions/ActivateSource.cs b/src/LibCecTray/controller/actions/ActivateSource.cs
new file mode 100644 (file)
index 0000000..44d2d50
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited.  All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing       <license@pulse-eight.com>
+ *     http://www.pulse-eight.com/
+ *     http://www.pulse-eight.net/
+ */
+
+using CecSharp;
+using LibCECTray.Properties;
+
+namespace LibCECTray.controller.actions
+{
+  class ActivateSource : UpdateProcess
+  {
+    public ActivateSource(LibCecSharp lib)
+    {
+      _lib = lib;
+    }
+
+    public override void Process()
+    {
+      SendEvent(UpdateEventType.StatusText, Resources.action_activating_source);
+      SendEvent(UpdateEventType.ProgressBar, 50);
+
+      var bResult = _lib.SetActiveSource(CecDeviceType.Reserved);
+      SendEvent(UpdateEventType.ProgressBar, 100);
+    }
+
+    private readonly LibCecSharp _lib;
+  }
+}
index bf4e05a746af9a0282af435e19f08a4d289767eb..3f7c09422aa0a86e9aa21ab2da6714c135ccdf44 100644 (file)
@@ -55,7 +55,7 @@ namespace LibCECTray.ui
       Text = Resources.app_name;
       InitializeComponent();
 
-      _sstimer.Interval = 1000;
+      _sstimer.Interval = 5000;
       _sstimer.Tick += ScreensaverActiveCheck;
       _sstimer.Enabled = false;
 
@@ -112,9 +112,11 @@ namespace LibCECTray.ui
       if (msg.Msg == WM_SYSCOMMAND && (msg.WParam.ToInt32() & 0xfff0) == SC_SCREENSAVE)
       {
         // there's no event for screensaver exit
-        _sstimer.Enabled = true;
-        OnSleep();
-        return;
+        if (!_sstimer.Enabled)
+        {
+          _sstimer.Enabled = true;
+          Controller.CECActions.SendStandby(CecLogicalAddress.Broadcast);
+        }
       }
       else if (msg.Msg == WM_POWERBROADCAST)
       {
@@ -164,7 +166,7 @@ namespace LibCECTray.ui
       if (!IsScreensaverActive())
       {
         _sstimer.Enabled = false;
-        OnWake();
+        Controller.CECActions.ActivateSource();
       }
     }
 
@@ -182,7 +184,9 @@ namespace LibCECTray.ui
 
     private void OnSleep()
     {
-      Controller.Close();
+      Controller.CECActions.SuppressUpdates = true;
+      AsyncDisconnect dc = new AsyncDisconnect(Controller);
+      (new Thread(dc.Process)).Start();
     }
 
     public override sealed string Text
@@ -201,9 +205,7 @@ namespace LibCECTray.ui
       Hide();
       if (disposing)
       {
-        Controller.CECActions.SuppressUpdates = true;
-        AsyncDisconnect dc = new AsyncDisconnect(Controller);
-        (new Thread(dc.Process)).Start();
+        OnSleep();
       }
       if (disposing && (components != null))
       {
@@ -299,7 +301,7 @@ namespace LibCECTray.ui
 
     private void BActivateSourceClick(object sender, EventArgs e)
     {
-      Controller.CECActions.ActivateSource(GetTargetDevice());
+      Controller.CECActions.SetStreamPath(GetTargetDevice());
     }
 
     private void CbCommandDestinationSelectedIndexChanged(object sender, EventArgs e)
index 581a41797fb8ff189431bfea849d33374aabea86..1feed3bef862357e73980d1c2968af5ec255f98a 100644 (file)
@@ -72,7 +72,7 @@ namespace LibCECTray.ui
     {
       SetControlVisible(lInactiveSource, false);
       SetControlVisible(lActiveSource, true);
-      _controller.CECActions.ActivateSource(Address);
+      _controller.CECActions.SetStreamPath(Address);
     }
 
     private void LStandbyLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)