summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2013-05-19 16:49:50 +0000
committersr55 <[email protected]>2013-05-19 16:49:50 +0000
commit39d5addd4f0772fe45811be4a3b1e3305785866e (patch)
treef9a07819ae96f76af0f5bdfc9c3019256b99ada3 /win/CS/HandBrakeWPF/Services
parent67a224af55647590e886808285132d5955ed9333 (diff)
WinGui: Rectored some Encode/Queue service code. This restoes "Quit HandBrake" when done option.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5485 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Services')
-rw-r--r--win/CS/HandBrakeWPF/Services/Interfaces/INotificationService.cs14
-rw-r--r--win/CS/HandBrakeWPF/Services/Interfaces/IPrePostActionService.cs18
-rw-r--r--win/CS/HandBrakeWPF/Services/PrePostActionService.cs159
3 files changed, 190 insertions, 1 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Interfaces/INotificationService.cs b/win/CS/HandBrakeWPF/Services/Interfaces/INotificationService.cs
index d955bb55c..8a20c274e 100644
--- a/win/CS/HandBrakeWPF/Services/Interfaces/INotificationService.cs
+++ b/win/CS/HandBrakeWPF/Services/Interfaces/INotificationService.cs
@@ -1,5 +1,17 @@
-namespace HandBrakeWPF.Services.Interfaces
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="INotificationService.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Defines the INotificationService type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services.Interfaces
{
+ /// <summary>
+ /// The NotificationService interface.
+ /// </summary>
public interface INotificationService
{
}
diff --git a/win/CS/HandBrakeWPF/Services/Interfaces/IPrePostActionService.cs b/win/CS/HandBrakeWPF/Services/Interfaces/IPrePostActionService.cs
new file mode 100644
index 000000000..fcd164a69
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Services/Interfaces/IPrePostActionService.cs
@@ -0,0 +1,18 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="IPrePostActionService.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Defines the IPrePostActionService type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services.Interfaces
+{
+ /// <summary>
+ /// The WhenDoneService interface.
+ /// </summary>
+ public interface IPrePostActionService
+ {
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
new file mode 100644
index 000000000..ce4eee423
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
@@ -0,0 +1,159 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="WhenDoneService.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Defines the WhenDoneService type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services
+{
+ using System.Diagnostics;
+ using System.Windows.Forms;
+
+ using Caliburn.Micro;
+
+ using HandBrake.ApplicationServices.Services.Interfaces;
+ using HandBrake.ApplicationServices.Utilities;
+
+ using HandBrakeWPF.Services.Interfaces;
+
+ using Application = System.Windows.Application;
+
+ /// <summary>
+ /// The when done service.
+ /// </summary>
+ public class PrePostActionService : IPrePostActionService
+ {
+ /// <summary>
+ /// The queue processor.
+ /// </summary>
+ private readonly IQueueProcessor queueProcessor;
+
+ /// <summary>
+ /// The user setting service.
+ /// </summary>
+ private readonly IUserSettingService userSettingService;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PrePostActionService"/> class.
+ /// </summary>
+ /// <param name="queueProcessor">
+ /// The queue processor.
+ /// </param>
+ /// <param name="userSettingService">
+ /// The user Setting Service.
+ /// </param>
+ public PrePostActionService(IQueueProcessor queueProcessor, IUserSettingService userSettingService)
+ {
+ this.queueProcessor = queueProcessor;
+ this.userSettingService = userSettingService;
+
+ this.queueProcessor.QueueCompleted += QueueProcessorQueueCompleted;
+ this.queueProcessor.EncodeService.EncodeCompleted += EncodeService_EncodeCompleted;
+ this.queueProcessor.EncodeService.EncodeStarted += EncodeService_EncodeStarted;
+ }
+
+ /// <summary>
+ /// The encode service_ encode started.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void EncodeService_EncodeStarted(object sender, System.EventArgs e)
+ {
+ if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PreventSleep))
+ {
+ Win32.PreventSleep();
+ }
+ }
+
+ /// <summary>
+ /// The encode service_ encode completed.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The EncodeCompletedEventArgs.
+ /// </param>
+ private void EncodeService_EncodeCompleted(object sender, HandBrake.ApplicationServices.EventArgs.EncodeCompletedEventArgs e)
+ {
+ // Send the file to the users requested applicaiton
+ if (e.Successful)
+ {
+ this.SendToApplication(e.FileName);
+ }
+
+ // Allow the system to sleep again.
+ Execute.OnUIThread(() =>
+ {
+ if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PreventSleep))
+ {
+ Win32.AllowSleep();
+ }
+ });
+ }
+
+ /// <summary>
+ /// The queue processor queue completed event handler.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void QueueProcessorQueueCompleted(object sender, System.EventArgs e)
+ {
+ // Do something whent he encode ends.
+ switch (this.userSettingService.GetUserSetting<string>(UserSettingConstants.WhenCompleteAction))
+ {
+ case "Shutdown":
+ Process.Start("Shutdown", "-s -t 60");
+ break;
+ case "Log off":
+ Win32.ExitWindowsEx(0, 0);
+ break;
+ case "Suspend":
+ System.Windows.Forms.Application.SetSuspendState(PowerState.Suspend, true, true);
+ break;
+ case "Hibernate":
+ System.Windows.Forms.Application.SetSuspendState(PowerState.Hibernate, true, true);
+ break;
+ case "Lock System":
+ Win32.LockWorkStation();
+ break;
+ case "Quit HandBrake":
+ Execute.OnUIThread(() => Application.Current.Shutdown());
+ break;
+ }
+ }
+
+ /// <summary>
+ /// Send a file to a 3rd party application after encoding has completed.
+ /// </summary>
+ /// <param name="file">
+ /// The file path
+ /// </param>
+ private void SendToApplication(string file)
+ {
+ if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.SendFile) &&
+ !string.IsNullOrEmpty(this.userSettingService.GetUserSetting<string>(UserSettingConstants.SendFileTo)))
+ {
+ string args = string.Format(
+ "{0} \"{1}\"",
+ this.userSettingService.GetUserSetting<string>(UserSettingConstants.SendFileToArgs),
+ file);
+ var vlc =
+ new ProcessStartInfo(
+ this.userSettingService.GetUserSetting<string>(UserSettingConstants.SendFileTo), args);
+ Process.Start(vlc);
+ }
+ }
+ }
+}