From 39d5addd4f0772fe45811be4a3b1e3305785866e Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 19 May 2013 16:49:50 +0000 Subject: 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 --- win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 2 + .../Services/Interfaces/INotificationService.cs | 14 +- .../Services/Interfaces/IPrePostActionService.cs | 18 +++ .../HandBrakeWPF/Services/PrePostActionService.cs | 159 +++++++++++++++++++++ win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs | 1 + win/CS/HandBrakeWPF/UserSettingConstants.cs | 25 ++++ win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 9 +- win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 26 ++-- win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs | 19 +-- 9 files changed, 242 insertions(+), 31 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Services/Interfaces/IPrePostActionService.cs create mode 100644 win/CS/HandBrakeWPF/Services/PrePostActionService.cs (limited to 'win/CS/HandBrakeWPF') diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index d7c81d861..21de3a905 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -166,9 +166,11 @@ + + 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 +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the INotificationService type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Services.Interfaces { + /// + /// The NotificationService interface. + /// 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 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the IPrePostActionService type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Services.Interfaces +{ + /// + /// The WhenDoneService interface. + /// + 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 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the WhenDoneService type. +// +// -------------------------------------------------------------------------------------------------------------------- + +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; + + /// + /// The when done service. + /// + public class PrePostActionService : IPrePostActionService + { + /// + /// The queue processor. + /// + private readonly IQueueProcessor queueProcessor; + + /// + /// The user setting service. + /// + private readonly IUserSettingService userSettingService; + + /// + /// Initializes a new instance of the class. + /// + /// + /// The queue processor. + /// + /// + /// The user Setting Service. + /// + 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; + } + + /// + /// The encode service_ encode started. + /// + /// + /// The sender. + /// + /// + /// The e. + /// + private void EncodeService_EncodeStarted(object sender, System.EventArgs e) + { + if (this.userSettingService.GetUserSetting(UserSettingConstants.PreventSleep)) + { + Win32.PreventSleep(); + } + } + + /// + /// The encode service_ encode completed. + /// + /// + /// The sender. + /// + /// + /// The EncodeCompletedEventArgs. + /// + 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(UserSettingConstants.PreventSleep)) + { + Win32.AllowSleep(); + } + }); + } + + /// + /// The queue processor queue completed event handler. + /// + /// + /// The sender. + /// + /// + /// The e. + /// + private void QueueProcessorQueueCompleted(object sender, System.EventArgs e) + { + // Do something whent he encode ends. + switch (this.userSettingService.GetUserSetting(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; + } + } + + /// + /// Send a file to a 3rd party application after encoding has completed. + /// + /// + /// The file path + /// + private void SendToApplication(string file) + { + if (this.userSettingService.GetUserSetting(UserSettingConstants.SendFile) && + !string.IsNullOrEmpty(this.userSettingService.GetUserSetting(UserSettingConstants.SendFileTo))) + { + string args = string.Format( + "{0} \"{1}\"", + this.userSettingService.GetUserSetting(UserSettingConstants.SendFileToArgs), + file); + var vlc = + new ProcessStartInfo( + this.userSettingService.GetUserSetting(UserSettingConstants.SendFileTo), args); + Process.Start(vlc); + } + } + } +} diff --git a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs index 6f3428de3..a384815ee 100644 --- a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs +++ b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs @@ -61,6 +61,7 @@ namespace HandBrakeWPF.Startup this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); + this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); // Commands this.windsorContainer.Register(Component.For().ImplementedBy().LifeStyle.Is(LifestyleType.Singleton)); diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs index 1f4c02fce..b70d88654 100644 --- a/win/CS/HandBrakeWPF/UserSettingConstants.cs +++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs @@ -200,6 +200,31 @@ namespace HandBrakeWPF /// Disable LibHb Features /// public const string DisableLibHbFeatures = "DisableLibHbFeatures"; + + /// + /// When Complete Action + /// + public const string WhenCompleteAction = "WhenCompleteAction"; + + /// + /// Send file enabled. + /// + public const string SendFile = "SendFile"; + + /// + /// Send file to application path + /// + public const string SendFileTo = "SendFileTo"; + + /// + /// Send file to arguments + /// + public const string SendFileToArgs = "SendFileToArgs"; + + /// + /// Prevent Sleep + /// + public const string PreventSleep = "PreventSleep"; #endregion } diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index fd465d480..bbcd093c5 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -205,10 +205,15 @@ namespace HandBrakeWPF.ViewModels /// /// /// The notification Service. - /// *** Leave in Constructor. *** TODO find out why? + /// *** Leave in Constructor. *** + /// + /// + /// The when Done Service. + /// *** Leave in Constructor. *** /// public MainViewModel(IUserSettingService userSettingService, IScanServiceWrapper scanService, IEncodeServiceWrapper encodeService, IPresetService presetService, - IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService, IDriveDetectService driveDetectService, INotificationService notificationService) + IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService, IDriveDetectService driveDetectService, INotificationService notificationService, + IPrePostActionService whenDoneService) { this.scanService = scanService; this.encodeService = encodeService; diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index bde7bc38c..4b61c4192 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -19,6 +19,8 @@ namespace HandBrakeWPF.ViewModels using System.Linq; using System.Windows; + using Caliburn.Micro; + using HandBrake.ApplicationServices; using HandBrake.ApplicationServices.Services.Interfaces; using HandBrake.ApplicationServices.Utilities; @@ -1482,15 +1484,15 @@ namespace HandBrakeWPF.ViewModels this.whenDoneOptions.Add("Hibernate"); this.whenDoneOptions.Add("Lock System"); this.whenDoneOptions.Add("Log off"); - // this.whenDoneOptions.Add("Quit HandBrake"); + this.whenDoneOptions.Add("Quit HandBrake"); this.WhenDone = userSettingService.GetUserSetting("WhenCompleteAction"); this.GrowlAfterEncode = userSettingService.GetUserSetting(UserSettingConstants.GrowlEncode); this.GrowlAfterQueue = userSettingService.GetUserSetting(UserSettingConstants.GrowlQueue); - this.SendFileAfterEncode = this.userSettingService.GetUserSetting(ASUserSettingConstants.SendFile); - this.SendFileTo = Path.GetFileNameWithoutExtension(this.userSettingService.GetUserSetting(ASUserSettingConstants.SendFileTo)) ?? string.Empty; - this.SendFileToPath = this.userSettingService.GetUserSetting(ASUserSettingConstants.SendFileTo) ?? string.Empty; - this.Arguments = this.userSettingService.GetUserSetting(ASUserSettingConstants.SendFileToArgs) ?? string.Empty; + this.SendFileAfterEncode = this.userSettingService.GetUserSetting(UserSettingConstants.SendFile); + this.SendFileTo = Path.GetFileNameWithoutExtension(this.userSettingService.GetUserSetting(UserSettingConstants.SendFileTo)) ?? string.Empty; + this.SendFileToPath = this.userSettingService.GetUserSetting(UserSettingConstants.SendFileTo) ?? string.Empty; + this.Arguments = this.userSettingService.GetUserSetting(UserSettingConstants.SendFileToArgs) ?? string.Empty; // ############################# // Output Settings @@ -1597,7 +1599,7 @@ namespace HandBrakeWPF.ViewModels this.priorityLevelOptions.Add("Low"); this.SelectedPriority = userSettingService.GetUserSetting(ASUserSettingConstants.ProcessPriority); - this.PreventSleep = userSettingService.GetUserSetting(ASUserSettingConstants.PreventSleep); + this.PreventSleep = userSettingService.GetUserSetting(UserSettingConstants.PreventSleep); // Log Verbosity Level this.logVerbosityOptions.Clear(); @@ -1820,12 +1822,12 @@ namespace HandBrakeWPF.ViewModels /* General */ this.userSettingService.SetUserSetting(UserSettingConstants.UpdateStatus, this.CheckForUpdates); this.userSettingService.SetUserSetting(UserSettingConstants.DaysBetweenUpdateCheck, this.CheckForUpdatesFrequency); - this.userSettingService.SetUserSetting(ASUserSettingConstants.WhenCompleteAction, this.WhenDone); + this.userSettingService.SetUserSetting(UserSettingConstants.WhenCompleteAction, this.WhenDone); this.userSettingService.SetUserSetting(UserSettingConstants.GrowlQueue, this.GrowlAfterQueue); this.userSettingService.SetUserSetting(UserSettingConstants.GrowlEncode, this.GrowlAfterEncode); - this.userSettingService.SetUserSetting(ASUserSettingConstants.SendFileTo, this.SendFileToPath); - this.userSettingService.SetUserSetting(ASUserSettingConstants.SendFile, this.SendFileAfterEncode); - this.userSettingService.SetUserSetting(ASUserSettingConstants.SendFileToArgs, this.Arguments); + this.userSettingService.SetUserSetting(UserSettingConstants.SendFileTo, this.SendFileToPath); + this.userSettingService.SetUserSetting(UserSettingConstants.SendFile, this.SendFileAfterEncode); + this.userSettingService.SetUserSetting(UserSettingConstants.SendFileToArgs, this.Arguments); /* Output Files */ this.userSettingService.SetUserSetting(UserSettingConstants.AutoNaming, this.AutomaticallyNameFiles); @@ -1852,7 +1854,7 @@ namespace HandBrakeWPF.ViewModels /* System and Logging */ userSettingService.SetUserSetting(ASUserSettingConstants.ProcessPriority, this.SelectedPriority); - userSettingService.SetUserSetting(ASUserSettingConstants.PreventSleep, this.PreventSleep); + userSettingService.SetUserSetting(UserSettingConstants.PreventSleep, this.PreventSleep); userSettingService.SetUserSetting(ASUserSettingConstants.Verbosity, this.SelectedVerbosity); userSettingService.SetUserSetting(ASUserSettingConstants.SaveLogWithVideo, this.CopyLogToEncodeDirectory); userSettingService.SetUserSetting(ASUserSettingConstants.SaveLogToCopyDirectory, this.CopyLogToSepcficedLocation); @@ -1935,7 +1937,7 @@ namespace HandBrakeWPF.ViewModels this.UpdateMessage = info.WasSuccessful ? "Update Downloaded" : "Update Failed. You can try downloading the update from http://handbrake.fr"; Process.Start(Path.Combine(Path.GetTempPath(), "handbrake-setup.exe")); - Application.Current.Shutdown(); + Execute.OnUIThread(() => Application.Current.Shutdown()); } /// diff --git a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs index 3b5bf33e8..bf7d46b3d 100644 --- a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs @@ -10,13 +10,11 @@ namespace HandBrakeWPF.ViewModels { using System; - using System.Collections.ObjectModel; using System.ComponentModel; using System.Windows; using Caliburn.Micro; - using HandBrake.ApplicationServices; using HandBrake.ApplicationServices.EventArgs; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Interfaces; @@ -31,13 +29,6 @@ namespace HandBrakeWPF.ViewModels /// public class QueueViewModel : ViewModelBase, IQueueViewModel { - /* - - * TODO FIX THE DRAP/DROP ADORNER! - */ - - - #region Constants and Fields /// @@ -82,9 +73,6 @@ namespace HandBrakeWPF.ViewModels /// /// Initializes a new instance of the class. /// - /// - /// The window manager. - /// /// /// The user Setting Service. /// @@ -94,7 +82,7 @@ namespace HandBrakeWPF.ViewModels /// /// The Error Service /// - public QueueViewModel(IWindowManager windowManager, IUserSettingService userSettingService, IQueueProcessor queueProcessor, IErrorService errorService) + public QueueViewModel(IUserSettingService userSettingService, IQueueProcessor queueProcessor, IErrorService errorService) { this.userSettingService = userSettingService; this.queueProcessor = queueProcessor; @@ -199,7 +187,7 @@ namespace HandBrakeWPF.ViewModels public void WhenDone(string action) { this.WhenDoneAction = action; - this.userSettingService.SetUserSetting(ASUserSettingConstants.WhenCompleteAction, action); + this.userSettingService.SetUserSetting(UserSettingConstants.WhenCompleteAction, action); } /// @@ -374,7 +362,7 @@ namespace HandBrakeWPF.ViewModels { this.Load(); - this.WhenDoneAction = this.userSettingService.GetUserSetting(ASUserSettingConstants.WhenCompleteAction); + this.WhenDoneAction = this.userSettingService.GetUserSetting(UserSettingConstants.WhenCompleteAction); this.queueProcessor.JobProcessingStarted += this.queueProcessor_JobProcessingStarted; this.queueProcessor.QueueCompleted += this.queueProcessor_QueueCompleted; @@ -429,7 +417,6 @@ namespace HandBrakeWPF.ViewModels e.EstimatedTimeLeft, e.ElapsedTime); } - }); } -- cgit v1.2.3