X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FLibCecTray%2Fcontroller%2Fapplications%2FApplicationController.cs;h=ae9a226f26cfba18f7bc84b94ee68404d08ff710;hb=bfea6e0a8ee4bc9e40c64ea68f22db69ac3cb26f;hp=310f30f8ef05e12f25dbf04ecb3ae320912fb895;hpb=cf3303fcf1e227b331e915a0397440bd1be3ca7f;p=deb_libcec.git diff --git a/src/LibCecTray/controller/applications/ApplicationController.cs b/src/LibCecTray/controller/applications/ApplicationController.cs index 310f30f..ae9a226 100644 --- a/src/LibCecTray/controller/applications/ApplicationController.cs +++ b/src/LibCecTray/controller/applications/ApplicationController.cs @@ -1,7 +1,7 @@ /* * This file is part of the libCEC(R) library. * - * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. + * 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. @@ -42,6 +42,8 @@ using Timer = System.Timers.Timer; namespace LibCECTray.controller.applications { + public delegate void OnApplicationRunningChanged(bool running); + /// /// Controls an application on the PC: send key presses, open the application, close it, etc. /// @@ -112,7 +114,20 @@ namespace LibCECTray.controller.applications var item = args.RowIndex < ButtonConfig.Count ? ButtonConfig[args.RowIndex] : null; if (item == null) return; - (new CecButtonConfigUI(item)).ShowDialog(); + if (args.ColumnIndex >= 0) + { + (new CecButtonConfigUI(item)).ShowDialog(); + } + else + { + var mappedButton = ButtonConfig[item.Key]; + if (mappedButton == null || mappedButton.Value.Empty()) + return; + + var controlWindow = FindInstance(); + if (controlWindow != IntPtr.Zero && item.Key.Duration == 0) + mappedButton.Value.Transmit(controlWindow); + } }; foreach (var item in _buttonConfig) @@ -190,12 +205,24 @@ namespace LibCECTray.controller.applications public virtual void Initialise() { Timer timer = new Timer { Interval = 1000, AutoReset = true }; - timer.Elapsed += delegate { UiControl.SetStartButtonEnabled(true); }; + timer.Elapsed += delegate { CheckApplicationEnabled(); }; timer.Start(); if (AutoStartApplication.Value) Start(false); } + + public event OnApplicationRunningChanged ApplicationRunningChanged; + + private void CheckApplicationEnabled() + { + var isRunning = IsRunning(); + if (isRunning != _applicationRunning && ApplicationRunningChanged != null) + ApplicationRunningChanged(isRunning); + + _applicationRunning = isRunning; + UiControl.SetStartButtonEnabled(!isRunning && !SuppressApplicationStart); + } #endregion #region Send input to the application @@ -221,7 +248,7 @@ namespace LibCECTray.controller.applications return false; var controlWindow = FindInstance(); - if (controlWindow != IntPtr.Zero && key.Duration == 0) + if (controlWindow != IntPtr.Zero && (key.Duration == 0 || key.Duration > 500)) return mappedButton.Value.Transmit(controlWindow); return false; @@ -353,18 +380,7 @@ namespace LibCECTray.controller.applications private CecButtonConfig _buttonConfig; public CecButtonConfig ButtonConfig { - get - { - if (_buttonConfig == null) - { - _buttonConfig = new CecButtonConfig(this); - foreach (CecUserControlCode key in Enum.GetValues(typeof(CecUserControlCode))) - _buttonConfig.Add(new CecButtonConfigItem(this, (new CecKeypress { Keycode = key }))); - - _buttonConfig.Load(); - } - return _buttonConfig; - } + get { return _buttonConfig ?? (_buttonConfig = new CecButtonConfig(this)); } } public CECSettings Settings; @@ -388,6 +404,9 @@ namespace LibCECTray.controller.applications return !IsInternal; } } + + private bool _applicationRunning; + #endregion } }