summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs41
1 files changed, 41 insertions, 0 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs
index e578d9688..f1da43828 100644
--- a/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs
@@ -9,6 +9,8 @@
namespace HandBrakeWPF.ViewModels
{
+ using System.Collections.Generic;
+
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Parsing;
using HandBrake.Interop.Model.Encoding;
@@ -21,6 +23,11 @@ namespace HandBrakeWPF.ViewModels
public class EncoderOptionsViewModel : ViewModelBase, IEncoderOptionsViewModel, ITabInterface
{
/// <summary>
+ /// The cached options.
+ /// </summary>
+ private readonly Dictionary<VideoEncoder, string> cachedOptions = new Dictionary<VideoEncoder, string>();
+
+ /// <summary>
/// Initializes a new instance of the <see cref="EncoderOptionsViewModel"/> class.
/// </summary>
public EncoderOptionsViewModel()
@@ -34,6 +41,16 @@ namespace HandBrakeWPF.ViewModels
public EncodeTask Task { get; set; }
/// <summary>
+ /// Gets or sets the preset.
+ /// </summary>
+ public Preset Preset { get; set; }
+
+ /// <summary>
+ /// Gets or sets the current video encoder.
+ /// </summary>
+ public VideoEncoder CurrentVideoEncoder { get; set; }
+
+ /// <summary>
/// Gets or sets the options string.
/// </summary>
public string AdvancedOptionsString
@@ -64,6 +81,7 @@ namespace HandBrakeWPF.ViewModels
public void SetSource(Title selectedTitle, Preset currentPreset, EncodeTask task)
{
this.Task = task;
+ this.Preset = currentPreset;
this.NotifyOfPropertyChange(() => this.AdvancedOptionsString);
}
@@ -79,6 +97,7 @@ namespace HandBrakeWPF.ViewModels
public void SetPreset(Preset preset, EncodeTask task)
{
this.Task = task;
+ this.Preset = preset;
this.AdvancedOptionsString = preset.Task.AdvancedEncoderOptions;
}
@@ -102,6 +121,28 @@ namespace HandBrakeWPF.ViewModels
/// </param>
public void SetEncoder(VideoEncoder encoder)
{
+ // Cache the existing string so it can be reused if the user changes the encoder back.
+ if (!string.IsNullOrEmpty(this.AdvancedOptionsString))
+ {
+ this.cachedOptions[CurrentVideoEncoder] = this.AdvancedOptionsString;
+ }
+
+ this.CurrentVideoEncoder = encoder;
+
+ // Set the option from the cached version if we have one.
+ string advacnedOptionsString;
+ if (cachedOptions.TryGetValue(encoder, out advacnedOptionsString)
+ && !string.IsNullOrEmpty(advacnedOptionsString))
+ {
+ this.AdvancedOptionsString = advacnedOptionsString;
+ }
+ else
+ {
+ this.AdvancedOptionsString = this.Preset != null && this.Preset.Task != null
+ && !string.IsNullOrEmpty(this.Preset.Task.AdvancedEncoderOptions)
+ ? this.Preset.Task.AdvancedEncoderOptions
+ : string.Empty;
+ }
}
/// <summary>