diff options
author | sr55 <[email protected]> | 2019-06-24 21:15:49 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2019-06-24 21:16:01 +0100 |
commit | b52b25d167d76106c8666c788c17e7a33f713f4d (patch) | |
tree | a01ff14c78959c9b4151819c78e46701c1cbf53b /win/CS/HandBrakeWPF/ViewModels | |
parent | 1613a41853551dedc5b3219f05ed32aacbc85b79 (diff) |
WinGui: Refactor "When Done" to use an enum to avoid language issues. Also change "suspend" to "sleep" to be consistent with the OS. Fixes #2162
Diffstat (limited to 'win/CS/HandBrakeWPF/ViewModels')
8 files changed, 58 insertions, 59 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/CountdownAlertViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/CountdownAlertViewModel.cs index ccee60870..a6d3ae2c7 100644 --- a/win/CS/HandBrakeWPF/ViewModels/CountdownAlertViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/CountdownAlertViewModel.cs @@ -12,7 +12,9 @@ namespace HandBrakeWPF.ViewModels using System;
using System.Windows.Threading;
+ using HandBrakeWPF.Model.Options;
using HandBrakeWPF.Properties;
+ using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
/// <summary>
@@ -115,12 +117,12 @@ namespace HandBrakeWPF.ViewModels /// <param name="actionMsg">
/// The action.
/// </param>
- public void SetAction(string actionMsg)
+ public void SetAction(WhenDone actionMsg)
{
this.IsCancelled = false;
this.Ticks = 0;
timer.Start();
- this.action = actionMsg;
+ this.action = EnumHelper<WhenDone>.GetDisplay(actionMsg);
}
#endregion
diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/ICountdownAlertViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/ICountdownAlertViewModel.cs index 0dac356f3..e779921f8 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/ICountdownAlertViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/ICountdownAlertViewModel.cs @@ -9,6 +9,8 @@ namespace HandBrakeWPF.ViewModels.Interfaces
{
+ using HandBrakeWPF.Model.Options;
+
/// <summary>
/// The Countdown Alert View Model Interface
/// </summary>
@@ -25,6 +27,6 @@ namespace HandBrakeWPF.ViewModels.Interfaces /// <param name="action">
/// The action.
/// </param>
- void SetAction(string action);
+ void SetAction(WhenDone action);
}
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IQueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IQueueViewModel.cs index 07f2a06bf..0ee439e81 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IQueueViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IQueueViewModel.cs @@ -9,6 +9,8 @@ namespace HandBrakeWPF.ViewModels.Interfaces
{
+ using HandBrakeWPF.Model.Options;
+
/// <summary>
/// The Queue View Model Interface
/// </summary>
@@ -25,7 +27,7 @@ namespace HandBrakeWPF.ViewModels.Interfaces /// <param name="saveChange">
/// Save the change to the setting. Use false when updating UI.
/// </param>
- void WhenDone(string action, bool saveChange);
+ void WhenDone(int action, bool saveChange);
/// <summary>
/// The import.
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index c93a005d3..c1cd1aafb 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -1141,7 +1141,7 @@ namespace HandBrakeWPF.ViewModels // Reset WhenDone if necessary.
if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.ResetWhenDoneAction))
{
- this.WhenDone("Do nothing");
+ this.WhenDone(0);
}
// Log Cleaning
@@ -1359,7 +1359,7 @@ namespace HandBrakeWPF.ViewModels if (File.Exists(this.CurrentTask.Destination))
{
- FileOverwriteBehaviour behaviour = (FileOverwriteBehaviour)this.userSettingService.GetUserSetting<int>(UserSettingConstants.FileOverwriteBehaviour, typeof(int));
+ FileOverwriteBehaviour behaviour = (FileOverwriteBehaviour)this.userSettingService.GetUserSetting<int>(UserSettingConstants.FileOverwriteBehaviour);
if (behaviour == FileOverwriteBehaviour.Ask)
{
MessageBoxResult result = this.errorService.ShowMessageBox(string.Format(Resources.Main_QueueOverwritePrompt, Path.GetFileName(this.CurrentTask.Destination)), Resources.Question, MessageBoxButton.YesNo, MessageBoxImage.Question);
@@ -1694,7 +1694,7 @@ namespace HandBrakeWPF.ViewModels /// Pass on the "When Done" Action to the queue view model.
/// </summary>
/// <param name="action">action</param>
- public void WhenDone(string action)
+ public void WhenDone(int action)
{
this.QueueViewModel?.WhenDone(action, true);
}
@@ -1766,9 +1766,7 @@ namespace HandBrakeWPF.ViewModels };
saveFileDialog.OverwritePrompt =
- (FileOverwriteBehaviour)this.userSettingService.GetUserSetting<int>(
- UserSettingConstants.FileOverwriteBehaviour,
- typeof(int)) == FileOverwriteBehaviour.Ask;
+ (FileOverwriteBehaviour)this.userSettingService.GetUserSetting<int>(UserSettingConstants.FileOverwriteBehaviour) == FileOverwriteBehaviour.Ask;
string extension = Path.GetExtension(this.CurrentTask.Destination);
@@ -2659,7 +2657,7 @@ namespace HandBrakeWPF.ViewModels switch (e.Key)
{
case UserSettingConstants.WhenCompleteAction:
- this.QueueViewModel.WhenDone(this.userSettingService.GetUserSetting<string>(UserSettingConstants.WhenCompleteAction), false);
+ this.QueueViewModel.WhenDone(this.userSettingService.GetUserSetting<int>(UserSettingConstants.WhenCompleteAction), false);
break;
case UserSettingConstants.ShowAddAllToQueue:
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 1fcb2379e..4375e2a08 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -80,8 +80,8 @@ namespace HandBrakeWPF.ViewModels private string sendFileTo;
private string sendFileToPath;
private string vlcPath;
- private string whenDone;
- private BindingList<string> whenDoneOptions = new BindingList<string>();
+ private WhenDone whenDone;
+ private BindingList<WhenDone> whenDoneOptions = new BindingList<WhenDone>();
private bool clearQueueOnEncodeCompleted;
private OptionsTab selectedTab;
private string updateMessage;
@@ -351,7 +351,7 @@ namespace HandBrakeWPF.ViewModels /// <summary>
/// Gets or sets WhenDone.
/// </summary>
- public string WhenDone
+ public WhenDone WhenDone
{
get
{
@@ -366,19 +366,13 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
- /// Gets or sets WhenDoneOptions.
+ /// Gets WhenDoneOptions.
/// </summary>
- public BindingList<string> WhenDoneOptions
+ public BindingList<WhenDone> WhenDoneOptions
{
get
{
- return this.whenDoneOptions;
- }
-
- set
- {
- this.whenDoneOptions = value;
- this.NotifyOfPropertyChange("WhenDoneOptions");
+ return new BindingList<WhenDone>(EnumHelper<WhenDone>.GetEnumList().ToList());
}
}
@@ -1470,7 +1464,7 @@ namespace HandBrakeWPF.ViewModels this.checkForUpdatesFrequencies.Add("Weekly");
this.checkForUpdatesFrequencies.Add("Monthly");
- this.CheckForUpdatesFrequency = this.userSettingService.GetUserSetting<int>(UserSettingConstants.DaysBetweenUpdateCheck, typeof(int));
+ this.CheckForUpdatesFrequency = this.userSettingService.GetUserSetting<int>(UserSettingConstants.DaysBetweenUpdateCheck);
if (this.CheckForUpdatesFrequency > 1)
{
this.CheckForUpdatesFrequency = 1;
@@ -1489,18 +1483,18 @@ namespace HandBrakeWPF.ViewModels // On Encode Completion Action
this.whenDoneOptions.Clear();
- this.whenDoneOptions.Add("Do nothing");
- this.whenDoneOptions.Add("Shutdown");
- this.whenDoneOptions.Add("Suspend");
- this.whenDoneOptions.Add("Hibernate");
- this.whenDoneOptions.Add("Lock System");
- this.whenDoneOptions.Add("Log off");
- this.whenDoneOptions.Add("Quit HandBrake");
-
- this.WhenDone = userSettingService.GetUserSetting<string>(UserSettingConstants.WhenCompleteAction);
+ this.whenDoneOptions.Add(WhenDone.DoNothing);
+ this.whenDoneOptions.Add(WhenDone.Shutdown);
+ this.whenDoneOptions.Add(WhenDone.Sleep);
+ this.whenDoneOptions.Add(WhenDone.Hibernate);
+ this.whenDoneOptions.Add(WhenDone.LockSystem);
+ this.whenDoneOptions.Add(WhenDone.LogOff);
+ this.whenDoneOptions.Add(WhenDone.QuickHandBrake);
+
+ this.WhenDone = (WhenDone)this.userSettingService.GetUserSetting<int>(UserSettingConstants.WhenCompleteAction);
if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.ResetWhenDoneAction))
{
- this.WhenDone = "Do nothing";
+ this.WhenDone = WhenDone.DoNothing;
}
this.SendFileAfterEncode = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.SendFile);
@@ -1535,7 +1529,7 @@ namespace HandBrakeWPF.ViewModels this.mp4ExtensionOptions.Add("Automatic");
this.mp4ExtensionOptions.Add("Always use MP4");
this.mp4ExtensionOptions.Add("Always use M4V");
- this.SelectedMp4Extension = this.userSettingService.GetUserSetting<int>(UserSettingConstants.UseM4v, typeof(int));
+ this.SelectedMp4Extension = this.userSettingService.GetUserSetting<int>(UserSettingConstants.UseM4v);
// Remove Underscores
this.RemoveUnderscores = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameRemoveUnderscore);
@@ -1548,11 +1542,11 @@ namespace HandBrakeWPF.ViewModels this.FileOverwriteBehaviourList = new BindingList<FileOverwriteBehaviour>();
this.FileOverwriteBehaviourList.Add(FileOverwriteBehaviour.Ask);
this.FileOverwriteBehaviourList.Add(FileOverwriteBehaviour.ForceOverwrite);
- this.SelectedOverwriteBehaviour = this.userSettingService.GetUserSetting<int>(UserSettingConstants.FileOverwriteBehaviour, typeof(int));
+ this.SelectedOverwriteBehaviour = this.userSettingService.GetUserSetting<int>(UserSettingConstants.FileOverwriteBehaviour);
// Collision behaviour
this.AutonameFileCollisionBehaviours = new BindingList<AutonameFileCollisionBehaviour>() { AutonameFileCollisionBehaviour.AppendNumber, AutonameFileCollisionBehaviour.Prefix, AutonameFileCollisionBehaviour.Postfix };
- this.SelectedCollisionBehaviour = this.userSettingService.GetUserSetting<int>(UserSettingConstants.AutonameFileCollisionBehaviour, typeof(int));
+ this.SelectedCollisionBehaviour = this.userSettingService.GetUserSetting<int>(UserSettingConstants.AutonameFileCollisionBehaviour);
this.PrePostFilenameText = this.userSettingService.GetUserSetting<string>(UserSettingConstants.AutonameFilePrePostString);
// #############################
@@ -1566,7 +1560,7 @@ namespace HandBrakeWPF.ViewModels // Video
// #############################
this.EnableQuickSyncDecoding = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.EnableQuickSyncDecoding);
- this.SelectedScalingMode = this.userSettingService.GetUserSetting<VideoScaler>(UserSettingConstants.ScalingMode, typeof(int));
+ this.SelectedScalingMode = this.userSettingService.GetUserSetting<VideoScaler>(UserSettingConstants.ScalingMode);
this.UseQSVDecodeForNonQSVEnc = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.UseQSVDecodeForNonQSVEnc);
this.EnableQuickSyncEncoding = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.EnableQuickSyncEncoding);
@@ -1595,7 +1589,7 @@ namespace HandBrakeWPF.ViewModels this.logVerbosityOptions.Add(0);
this.logVerbosityOptions.Add(1);
this.logVerbosityOptions.Add(2);
- this.SelectedVerbosity = userSettingService.GetUserSetting<int>(UserSettingConstants.Verbosity, typeof(int));
+ this.SelectedVerbosity = userSettingService.GetUserSetting<int>(UserSettingConstants.Verbosity);
// Logs
this.CopyLogToEncodeDirectory = userSettingService.GetUserSetting<bool>(UserSettingConstants.SaveLogWithVideo);
@@ -1627,7 +1621,7 @@ namespace HandBrakeWPF.ViewModels this.PreviewPicturesToScan.Add(50);
this.PreviewPicturesToScan.Add(55);
this.PreviewPicturesToScan.Add(60);
- this.SelectedPreviewCount = this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount, typeof(int));
+ this.SelectedPreviewCount = this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount);
// x264 step
this.ConstantQualityGranularity.Clear();
@@ -1637,7 +1631,7 @@ namespace HandBrakeWPF.ViewModels this.SelectedGranulairty = userSettingService.GetUserSetting<double>(UserSettingConstants.X264Step).ToString("0.00", CultureInfo.InvariantCulture);
// Min Title Length
- this.MinLength = this.userSettingService.GetUserSetting<int>(UserSettingConstants.MinScanDuration, typeof(int));
+ this.MinLength = this.userSettingService.GetUserSetting<int>(UserSettingConstants.MinScanDuration);
// Use dvdnav
this.DisableLibdvdNav = userSettingService.GetUserSetting<bool>(UserSettingConstants.DisableLibDvdNav);
@@ -1648,7 +1642,7 @@ namespace HandBrakeWPF.ViewModels /// </summary>
public void UpdateSettings()
{
- this.WhenDone = userSettingService.GetUserSetting<string>("WhenCompleteAction");
+ this.WhenDone = (WhenDone)this.userSettingService.GetUserSetting<int>(UserSettingConstants.WhenCompleteAction);
}
/// <summary>
@@ -1693,7 +1687,7 @@ namespace HandBrakeWPF.ViewModels this.userSettingService.SetUserSetting(UserSettingConstants.ShowQueueInline, this.ShowQueueInline);
/* When Done */
- this.userSettingService.SetUserSetting(UserSettingConstants.WhenCompleteAction, this.WhenDone);
+ this.userSettingService.SetUserSetting(UserSettingConstants.WhenCompleteAction, (int)this.WhenDone);
this.userSettingService.SetUserSetting(UserSettingConstants.ResetWhenDoneAction, this.ResetWhenDoneAction);
this.userSettingService.SetUserSetting(UserSettingConstants.WhenDonePerformActionImmediately, this.WhenDonePerformActionImmediately);
this.userSettingService.SetUserSetting(UserSettingConstants.PlaySoundWhenDone, this.PlaySoundWhenDone);
diff --git a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs index 0415a8c95..e86d8f488 100644 --- a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs @@ -23,6 +23,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.EventArgs;
using HandBrakeWPF.Extensions;
+ using HandBrakeWPF.Model.Options;
using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Queue.Interfaces;
@@ -47,7 +48,7 @@ namespace HandBrakeWPF.ViewModels private readonly IQueueService queueProcessor;
private string jobStatus;
private string jobsPending;
- private string whenDoneAction;
+ private WhenDone whenDoneAction;
private QueueTask selectedTask;
private bool isQueueRunning;
private double progressValue;
@@ -82,7 +83,7 @@ namespace HandBrakeWPF.ViewModels this.DisplayName = "Queue";
this.IsQueueRunning = false;
- this.WhenDoneAction = this.userSettingService.GetUserSetting<string>(UserSettingConstants.WhenCompleteAction);
+ this.WhenDoneAction = (WhenDone)this.userSettingService.GetUserSetting<int>(UserSettingConstants.WhenCompleteAction);
}
#endregion
@@ -147,7 +148,7 @@ namespace HandBrakeWPF.ViewModels /// <summary>
/// Gets or sets WhenDoneAction.
/// </summary>
- public string WhenDoneAction
+ public WhenDone WhenDoneAction
{
get
{
@@ -273,7 +274,7 @@ namespace HandBrakeWPF.ViewModels /// <param name="action">
/// The action.
/// </param>
- public void WhenDone(string action)
+ public void WhenDone(int action)
{
this.WhenDone(action, true);
}
@@ -287,9 +288,9 @@ namespace HandBrakeWPF.ViewModels /// <param name="saveChange">
/// Save the change to the setting. Use false when updating UI.
/// </param>
- public void WhenDone(string action, bool saveChange)
+ public void WhenDone(int action, bool saveChange)
{
- this.WhenDoneAction = action;
+ this.WhenDoneAction = (WhenDone)action;
if (saveChange)
{
diff --git a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs index 5a9c38383..afb3ea885 100644 --- a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs @@ -151,7 +151,7 @@ namespace HandBrakeWPF.ViewModels this.CanPlay = true;
this.useSystemDefaultPlayer = userSettingService.GetUserSetting<bool>(UserSettingConstants.DefaultPlayer);
- this.Duration = userSettingService.GetUserSetting<int>(UserSettingConstants.LastPreviewDuration, typeof(int));
+ this.Duration = userSettingService.GetUserSetting<int>(UserSettingConstants.LastPreviewDuration);
}
#endregion
@@ -238,7 +238,7 @@ namespace HandBrakeWPF.ViewModels {
get
{
- return this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount, typeof(int)) - 1;
+ return this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount) - 1;
}
}
@@ -345,7 +345,7 @@ namespace HandBrakeWPF.ViewModels {
List<int> startPoints = new List<int>();
for (int i = 1;
- i <= this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount, typeof(int));
+ i <= this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount);
i++)
{
startPoints.Add(i);
@@ -428,7 +428,7 @@ namespace HandBrakeWPF.ViewModels public void NextPreview()
{
- int maxPreview = this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount, typeof(int));
+ int maxPreview = this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount);
if ((this.SelectedPreviewImage + 1) == maxPreview)
{
return;
diff --git a/win/CS/HandBrakeWPF/ViewModels/SummaryViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/SummaryViewModel.cs index add04d299..771fbec6e 100644 --- a/win/CS/HandBrakeWPF/ViewModels/SummaryViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/SummaryViewModel.cs @@ -369,7 +369,7 @@ namespace HandBrakeWPF.ViewModels public void NextPreview() { - int maxPreview = this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount, typeof(int)); + int maxPreview = this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount); if (this.selectedPreview == maxPreview) { return; @@ -385,7 +385,7 @@ namespace HandBrakeWPF.ViewModels public void PreviousPreview() { - int maxPreview = this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount, typeof(int)); + int maxPreview = this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount); if (this.selectedPreview <= 1) { return; @@ -410,7 +410,7 @@ namespace HandBrakeWPF.ViewModels this.IsPreviousPreviewControlVisible = false; } - if (this.selectedPreview < this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount, typeof(int))) + if (this.selectedPreview < this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount)) { this.IsNextPreviewControlVisible = true; } @@ -441,7 +441,7 @@ namespace HandBrakeWPF.ViewModels // Make sure the output extension is set correctly based on the users preferences and selection. if (newExtension == ".mp4" || newExtension == ".m4v") { - switch (this.userSettingService.GetUserSetting<int>(UserSettingConstants.UseM4v, typeof(int))) + switch (this.userSettingService.GetUserSetting<int>(UserSettingConstants.UseM4v)) { case 0: // Auto newExtension = MP4Helper.RequiresM4v(this.Task) ? ".m4v" : ".mp4"; @@ -499,7 +499,7 @@ namespace HandBrakeWPF.ViewModels this.FiltersInfo = this.GetFilterDescription(); this.NotifyOfPropertyChange(() => this.FiltersInfo); - // Picutre Section + // Picture Section this.DimensionInfo = string.Format("{0}x{1} {2}, {3}x{4} {5}", this.Task.Width, this.Task.Height, Resources.SummaryView_storage, this.Task.DisplayWidth, this.Task.Height, Resources.SummaryView_display); this.NotifyOfPropertyChange(() => this.DimensionInfo); @@ -507,7 +507,7 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange(() => this.AspectInfo); // Preview - this.PreviewInfo = string.Format(Resources.SummaryView_PreviewInfo, this.selectedPreview, this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount, typeof(int))); + this.PreviewInfo = string.Format(Resources.SummaryView_PreviewInfo, this.selectedPreview, this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount)); this.NotifyOfPropertyChange(() => this.PreviewInfo); this.ShowPreview = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.ShowPreviewOnSummaryTab); |