1 // --------------------------------------------------------------------------------------------------------------------
2 // <copyright file="SubtitleTrack.cs" company="HandBrake Project (http://handbrake.fr)">
3 //   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
4 // </copyright>
5 // <summary>
6 //   Subtitle Information
7 // </summary>
8 // --------------------------------------------------------------------------------------------------------------------
9 
10 namespace HandBrakeWPF.Services.Encode.Model.Models
11 {
12     using Caliburn.Micro;
13 
14     using HandBrake.Interop.Utilities;
15 
16     using HandBrakeWPF.Services.Scan.Model;
17 
18     public class SubtitleTrack : PropertyChangedBase
19     {
20         #region Constants and Fields
21 
22         /// <summary>
23         /// The burned in backing field.
24         /// </summary>
25         private bool burned;
26 
27         /// <summary>
28         /// The is default backing field.
29         /// </summary>
30         private bool isDefault;
31 
32         /// <summary>
33         /// The source track.
34         /// </summary>
35         private Subtitle sourceTrack;
36 
37         /// <summary>
38         /// Backing field for the srt file name.
39         /// </summary>
40         private string srtFileName;
41 
42         /// <summary>
43         /// Backing field for Forced Subs
44         /// </summary>
45         private bool forced;
46 
47         private string srtLang;
48 
49         private string name;
50 
51         #endregion
52 
53         #region Constructors and Destructors
54 
55         /// <summary>
56         /// Initializes a new instance of the <see cref="SubtitleTrack"/> class.
57         /// </summary>
SubtitleTrack()58         public SubtitleTrack()
59         {
60         }
61 
62         /// <summary>
63         /// Initializes a new instance of the <see cref="SubtitleTrack"/> class.
64         /// Copy Constructor
65         /// </summary>
66         /// <param name="subtitle">
67         /// The subtitle.
68         /// </param>
SubtitleTrack(SubtitleTrack subtitle)69         public SubtitleTrack(SubtitleTrack subtitle)
70         {
71             this.Burned = subtitle.Burned;
72             this.Default = subtitle.Default;
73             this.Forced = subtitle.Forced;
74             this.sourceTrack = subtitle.SourceTrack;
75             this.SrtCharCode = subtitle.SrtCharCode;
76             this.SrtFileName = subtitle.SrtFileName;
77             this.SrtLang = subtitle.SrtLang;
78             this.SrtOffset = subtitle.SrtOffset;
79             this.SrtPath = subtitle.SrtPath;
80             this.SubtitleType = subtitle.SubtitleType;
81             this.SourceTrack = subtitle.SourceTrack;
82             this.Name = subtitle.Name;
83         }
84 
85         #endregion
86 
87         #region Properties
88 
89         /// <summary>
90         ///   Gets or sets a value indicating whether Burned.
91         /// </summary>
92         public bool Burned
93         {
94             get
95             {
96                 return this.burned;
97             }
98 
99             set
100             {
101                 if (!Equals(this.burned, value))
102                 {
103                     this.burned = value;
104                     this.NotifyOfPropertyChange(() => this.Burned);
105 
106                     if (value)
107                     {
108                         this.Default = false;
109                     }
110                 }
111             }
112         }
113 
114         /// <summary>
115         ///   Gets or sets a value indicating whether Default.
116         /// </summary>
117         public bool Default
118         {
119             get
120             {
121                 return this.isDefault;
122             }
123 
124             set
125             {
126                 if (!Equals(this.isDefault, value))
127                 {
128                     this.isDefault = value;
129                     this.NotifyOfPropertyChange(() => this.Default);
130 
131                     if (value)
132                     {
133                         this.Burned = false;
134                     }
135                 }
136             }
137         }
138 
139         /// <summary>
140         ///   Gets or sets a value indicating whether Forced.
141         /// </summary>
142         public bool Forced
143         {
144             get
145             {
146                 return this.forced;
147             }
148             set
149             {
150                 this.forced = value;
151                 this.NotifyOfPropertyChange(() => this.Forced);
152             }
153         }
154 
155         /// <summary>
156         ///   Gets or sets SourceTrack.
157         /// </summary>
158         public Subtitle SourceTrack
159         {
160             get
161             {
162                 return this.sourceTrack;
163             }
164 
165             set
166             {
167                 this.sourceTrack = value;
168                 this.NotifyOfPropertyChange(() => this.SourceTrack);
169                 if (this.sourceTrack != null)
170                 {
171                     this.SubtitleType = this.sourceTrack.SubtitleType;
172                 }
173 
174                 this.NotifyOfPropertyChange(() => this.SubtitleType);
175                 this.NotifyOfPropertyChange(() => this.CanBeBurned);
176                 this.NotifyOfPropertyChange(() => this.CanBeForced);
177 
178                 if (this.Forced && !this.CanBeForced)
179                 {
180                     this.Forced = false;
181                 }
182 
183                 if (this.Burned && !this.CanBeBurned)
184                 {
185                     this.Forced = false;
186                 }
187 
188                 if (this.sourceTrack != null)
189                 {
190                     this.Name = !string.IsNullOrEmpty(this.sourceTrack.Name) ? this.sourceTrack.Name : string.Empty;
191                 }
192             }
193         }
194 
195         /// <summary>
196         ///   Gets or sets the SRT Character Code
197         /// </summary>
198         public string SrtCharCode { get; set; }
199 
200         /// <summary>
201         ///   Gets or sets the SRT Filename
202         /// </summary>
203         public string SrtFileName
204         {
205             get
206             {
207                 return this.srtFileName;
208             }
209 
210             set
211             {
212                 this.srtFileName = value;
213                 this.NotifyOfPropertyChange(() => this.IsSrtSubtitle);
214             }
215         }
216 
217         /// <summary>
218         ///   Gets or sets the SRT Language
219         /// </summary>
220         public string SrtLang
221         {
222             get
223             {
224                 return this.srtLang;
225             }
226             set
227             {
228                 this.srtLang = value;
229                 string iso639 = LanguageUtilities.GetLanguageCode(this.srtLang);
230                 this.SrtLangCode = iso639;
231             }
232         }
233 
234         /// <summary>
235         /// Gets or sets the srt lang code.
236         /// </summary>
237         public string SrtLangCode { get; set; }
238 
239         /// <summary>
240         ///   Gets or sets the SRT Offset
241         /// </summary>
242         public int SrtOffset { get; set; }
243 
244         /// <summary>
245         ///   Gets or sets the Path to the SRT file
246         /// </summary>
247         public string SrtPath { get; set; }
248 
249         /// <summary>
250         ///   Gets or sets the type of the subtitle
251         /// </summary>
252         public SubtitleType SubtitleType { get; set; }
253 
254         public string Name
255         {
256             get => this.name;
257             set
258             {
259                 if (value == this.name) return;
260                 this.name = value;
261                 this.NotifyOfPropertyChange(() => this.Name);
262             }
263         }
264 
265         #endregion
266 
267         /// <summary>
268         /// Gets a value indicating whether CanForced.
269         /// </summary>
270         public bool CanBeForced
271         {
272             get
273             {
274                 if (this.SourceTrack != null)
275                 {
276                     return this.SourceTrack.CanForce || this.SourceTrack.IsFakeForeignAudioScanTrack;
277                 }
278 
279                 return false;
280             }
281         }
282 
283         /// <summary>
284         /// Gets a value indicating whether CanBeBurned.
285         /// </summary>
286         public bool CanBeBurned
287         {
288             get
289             {
290                 if (this.SourceTrack != null)
291                 {
292                     return this.SourceTrack.CanBurnIn || this.SourceTrack.IsFakeForeignAudioScanTrack;
293                 }
294 
295                 if (this.SubtitleType == SubtitleType.IMPORTSRT)
296                 {
297                     return true;
298                 }
299 
300                 if (this.SubtitleType == SubtitleType.IMPORTSSA)
301                 {
302                     return true;
303                 }
304 
305                 return false;
306             }
307         }
308 
309         /// <summary>
310         ///   Gets a value indicating whether this is an SRT subtitle.
311         /// </summary>
312         public bool IsSrtSubtitle
313         {
314             get
315             {
316                 return this.SrtFileName != "-" && this.SrtFileName != null;
317             }
318         }
319 
ToString()320         public override string ToString()
321         {
322             return string.Format("Subtitle Track: Title {0}", this.SrtFileName ?? this.SourceTrack.ToString());
323         }
324     }
325 }