// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// A Preset for encoding with.
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Services.Presets.Model
{
using HandBrakeWPF.Model.Audio;
using HandBrakeWPF.Model.Subtitles;
using HandBrakeWPF.Utilities;
using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
using PresetPictureSettingsMode = HandBrakeWPF.Model.Picture.PresetPictureSettingsMode;
///
/// A Preset for encoding with.
///
///
/// Using App Services PropertyChangedBase because Caliburn Micro has [DataContract] on their base class which causes json.net not to serialise properties without [DataContract]
/// https://github.com/Caliburn-Micro/Caliburn.Micro/issues/89
/// https://github.com/Caliburn-Micro/Caliburn.Micro/issues/96
///
public class Preset : PropertyChangedBase // Delibery not
{
#region Constants and Fields
///
/// The is default.
///
private bool isDefault;
#endregion
///
/// Initializes a new instance of the class.
///
public Preset()
{
}
///
/// Initializes a new instance of the class.
///
///
/// The preset.
///
public Preset(Preset preset)
{
this.Category = preset.Category;
this.Description = preset.Description;
this.IsBuildIn = preset.IsBuildIn;
this.Name = preset.Name;
this.PictureSettingsMode = preset.PictureSettingsMode;
this.Task = new EncodeTask(preset.Task);
this.AudioTrackBehaviours = new AudioBehaviours(preset.AudioTrackBehaviours);
this.SubtitleTrackBehaviours = new SubtitleBehaviours(preset.SubtitleTrackBehaviours);
}
#region Properties
///
/// Gets or sets the category which the preset resides under
///
public string Category { get; set; }
///
/// Gets or sets the Description for the preset
///
public string Description { get; set; }
///
/// Gets or sets a value indicating whether this is a built in preset
///
public bool IsBuildIn { get; set; }
///
/// Gets or sets a value indicating whether IsDefault.
///
public bool IsDefault
{
get
{
return this.isDefault;
}
set
{
this.isDefault = value;
this.NotifyOfPropertyChange(() => this.IsDefault);
}
}
///
/// Gets or sets the preset name
///
public string Name { get; set; }
///
/// Gets or sets PictureSettingsMode.
/// Source Maximum, Custom or None
///
public PresetPictureSettingsMode PictureSettingsMode { get; set; }
///
/// Gets or sets task.
///
public EncodeTask Task { get; set; }
///
/// Gets or sets the audio track behaviours.
///
public AudioBehaviours AudioTrackBehaviours { get; set; }
///
/// Gets or sets the subtitle track behaviours.
///
public SubtitleBehaviours SubtitleTrackBehaviours { get; set; }
#endregion
#region Public Methods
///
/// Update this preset.
/// The given parameters should be copy-constructed.
///
///
/// The task.
///
///
/// The audio behaviours.
///
///
/// The subtitle behaviours.
///
public void Update(EncodeTask task, AudioBehaviours audioBehaviours, SubtitleBehaviours subtitleBehaviours)
{
// Copy over Max Width / Height for the following picture settings modes.
if (this.PictureSettingsMode == PresetPictureSettingsMode.Custom
|| this.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)
{
task.MaxWidth = this.Task.MaxWidth;
task.MaxHeight = this.Task.MaxHeight;
}
this.Task = task;
this.AudioTrackBehaviours = new AudioBehaviours(audioBehaviours);
this.SubtitleTrackBehaviours = new SubtitleBehaviours(subtitleBehaviours);
}
///
/// Override the ToString Method
///
///
/// The Preset Name
///
public override string ToString()
{
return this.Name;
}
#endregion
///
/// The equals.
///
///
/// The other.
///
///
/// The .
///
protected bool Equals(Preset other)
{
return string.Equals(this.Name, other.Name);
}
///
/// The equals.
///
///
/// The obj.
///
///
/// The .
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != this.GetType())
{
return false;
}
return Equals((Preset)obj);
}
///
/// The get hash code.
///
///
/// The .
///
public override int GetHashCode()
{
return (this.Name != null ? this.Name.GetHashCode() : 0);
}
}
}