// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Subtitle Information // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Services.Encode.Model.Models { using Caliburn.Micro; using HandBrake.Interop.Utilities; using HandBrakeWPF.Services.Scan.Model; public class SubtitleTrack : PropertyChangedBase { #region Constants and Fields /// /// The burned in backing field. /// private bool burned; /// /// The is default backing field. /// private bool isDefault; /// /// The source track. /// private Subtitle sourceTrack; /// /// Backing field for the srt file name. /// private string srtFileName; /// /// Backing field for Forced Subs /// private bool forced; private string srtLang; private string name; #endregion #region Constructors and Destructors /// /// Initializes a new instance of the class. /// public SubtitleTrack() { } /// /// Initializes a new instance of the class. /// Copy Constructor /// /// /// The subtitle. /// public SubtitleTrack(SubtitleTrack subtitle) { this.Burned = subtitle.Burned; this.Default = subtitle.Default; this.Forced = subtitle.Forced; this.sourceTrack = subtitle.SourceTrack; this.SrtCharCode = subtitle.SrtCharCode; this.SrtFileName = subtitle.SrtFileName; this.SrtLang = subtitle.SrtLang; this.SrtOffset = subtitle.SrtOffset; this.SrtPath = subtitle.SrtPath; this.SubtitleType = subtitle.SubtitleType; this.SourceTrack = subtitle.SourceTrack; this.Name = subtitle.Name; } #endregion #region Properties /// /// Gets or sets a value indicating whether Burned. /// public bool Burned { get { return this.burned; } set { if (!Equals(this.burned, value)) { this.burned = value; this.NotifyOfPropertyChange(() => this.Burned); if (value) { this.Default = false; } } } } /// /// Gets or sets a value indicating whether Default. /// public bool Default { get { return this.isDefault; } set { if (!Equals(this.isDefault, value)) { this.isDefault = value; this.NotifyOfPropertyChange(() => this.Default); if (value) { this.Burned = false; } } } } /// /// Gets or sets a value indicating whether Forced. /// public bool Forced { get { return this.forced; } set { this.forced = value; this.NotifyOfPropertyChange(() => this.Forced); } } /// /// Gets or sets SourceTrack. /// public Subtitle SourceTrack { get { return this.sourceTrack; } set { this.sourceTrack = value; this.NotifyOfPropertyChange(() => this.SourceTrack); if (this.sourceTrack != null) { this.SubtitleType = this.sourceTrack.SubtitleType; } this.NotifyOfPropertyChange(() => this.SubtitleType); this.NotifyOfPropertyChange(() => this.CanBeBurned); this.NotifyOfPropertyChange(() => this.CanBeForced); if (this.Forced && !this.CanBeForced) { this.Forced = false; } if (this.Burned && !this.CanBeBurned) { this.Forced = false; } if (this.sourceTrack != null) { this.Name = !string.IsNullOrEmpty(this.sourceTrack.Name) ? this.sourceTrack.Name : string.Empty; } } } /// /// Gets or sets the SRT Character Code /// public string SrtCharCode { get; set; } /// /// Gets or sets the SRT Filename /// public string SrtFileName { get { return this.srtFileName; } set { this.srtFileName = value; this.NotifyOfPropertyChange(() => this.IsSrtSubtitle); } } /// /// Gets or sets the SRT Language /// public string SrtLang { get { return this.srtLang; } set { this.srtLang = value; string iso639 = LanguageUtilities.GetLanguageCode(this.srtLang); this.SrtLangCode = iso639; } } /// /// Gets or sets the srt lang code. /// public string SrtLangCode { get; set; } /// /// Gets or sets the SRT Offset /// public int SrtOffset { get; set; } /// /// Gets or sets the Path to the SRT file /// public string SrtPath { get; set; } /// /// Gets or sets the type of the subtitle /// public SubtitleType SubtitleType { get; set; } public string Name { get => this.name; set { if (value == this.name) return; this.name = value; this.NotifyOfPropertyChange(() => this.Name); } } #endregion /// /// Gets a value indicating whether CanForced. /// public bool CanBeForced { get { if (this.SourceTrack != null) { return this.SourceTrack.CanForce || this.SourceTrack.IsFakeForeignAudioScanTrack; } return false; } } /// /// Gets a value indicating whether CanBeBurned. /// public bool CanBeBurned { get { if (this.SourceTrack != null) { return this.SourceTrack.CanBurnIn || this.SourceTrack.IsFakeForeignAudioScanTrack; } if (this.SubtitleType == SubtitleType.IMPORTSRT) { return true; } if (this.SubtitleType == SubtitleType.IMPORTSSA) { return true; } return false; } } /// /// Gets a value indicating whether this is an SRT subtitle. /// public bool IsSrtSubtitle { get { return this.SrtFileName != "-" && this.SrtFileName != null; } } public override string ToString() { return string.Format("Subtitle Track: Title {0}", this.SrtFileName ?? this.SourceTrack.ToString()); } } }