// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// The Simple Encoder options screen
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.ViewModels
{
using System.Collections.Generic;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Parsing;
using HandBrake.Interop.Model.Encoding;
using HandBrakeWPF.ViewModels.Interfaces;
///
/// The Simple Encoder options screen
///
public class EncoderOptionsViewModel : ViewModelBase, IEncoderOptionsViewModel, ITabInterface
{
///
/// The cached options.
///
private readonly Dictionary cachedOptions = new Dictionary();
///
/// Initializes a new instance of the class.
///
public EncoderOptionsViewModel()
{
this.Task = new EncodeTask();
cachedOptions.Add(VideoEncoder.QuickSync, "async-depth=4");
}
///
/// Gets or sets the task.
///
public EncodeTask Task { get; set; }
///
/// Gets or sets the preset.
///
public Preset Preset { get; set; }
///
/// Gets or sets the current video encoder.
///
public VideoEncoder CurrentVideoEncoder { get; set; }
///
/// Gets or sets the options string.
///
public string AdvancedOptionsString
{
get
{
return this.Task.AdvancedEncoderOptions;
}
set
{
this.Task.AdvancedEncoderOptions = value;
this.NotifyOfPropertyChange(() => this.AdvancedOptionsString);
}
}
///
/// The set source.
///
///
/// The selected title.
///
///
/// The current preset.
///
///
/// The task.
///
public void SetSource(Title selectedTitle, Preset currentPreset, EncodeTask task)
{
this.Task = task;
this.Preset = currentPreset;
this.NotifyOfPropertyChange(() => this.AdvancedOptionsString);
}
///
/// The set preset.
///
///
/// The preset.
///
///
/// The task.
///
public void SetPreset(Preset preset, EncodeTask task)
{
this.Task = task;
this.Preset = preset;
this.AdvancedOptionsString = preset.Task.AdvancedEncoderOptions;
}
///
/// The update task.
///
///
/// The task.
///
public void UpdateTask(EncodeTask task)
{
this.Task = task;
this.NotifyOfPropertyChange(() => this.AdvancedOptionsString);
}
///
/// The set encoder.
///
///
/// The encoder.
///
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;
}
}
///
/// The clear.
///
public void Clear()
{
}
}
}