1 // --------------------------------------------------------------------------------------------------------------------
2 // <copyright file="Subtitle.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 //   An object that represents a subtitle associated with a Title, in a DVD
7 // </summary>
8 // --------------------------------------------------------------------------------------------------------------------
9 
10 namespace HandBrakeWPF.Services.Scan.Model
11 {
12     using System;
13     using System.Xml.Serialization;
14 
15     using HandBrake.Interop.Utilities;
16 
17     using HandBrakeWPF.Properties;
18     using HandBrakeWPF.Services.Encode.Model.Models;
19     using HandBrakeWPF.Utilities;
20 
21     /// <summary>
22     /// An object that represents a subtitle associated with a Title, in a DVD
23     /// </summary>
24     public class Subtitle
25     {
Subtitle()26         public Subtitle()
27         {
28         }
29 
Subtitle(int sourceId)30         public Subtitle(int sourceId)
31         {
32             this.SourceId = sourceId;
33         }
34 
Subtitle(int sourceId, int trackNumber, string language, string languageCode, SubtitleType subtitleType, bool canBurn, bool canForce, string name, bool isFakeForeignAudioScanTrack)35         public Subtitle(int sourceId, int trackNumber, string language, string languageCode, SubtitleType subtitleType, bool canBurn, bool canForce, string name, bool isFakeForeignAudioScanTrack)
36         {
37             this.SourceId = sourceId;
38             this.TrackNumber = trackNumber;
39             this.Language = language;
40             this.LanguageCode = languageCode;
41             this.SubtitleType = subtitleType;
42             this.CanBurnIn = canBurn;
43             this.CanForce = canForce;
44             this.Name = name;
45             this.IsFakeForeignAudioScanTrack = isFakeForeignAudioScanTrack;
46         }
47 
48         public int SourceId { get; set; }
49 
50         public int TrackNumber { get; set; }
51 
52         public string Language { get; set; }
53 
54         public string LanguageCode { get; set; }
55 
56         public string LanguageCodeClean
57         {
58             get
59             {
60                 if (this.LanguageCode != null)
61                 {
62                     return this.LanguageCode.Replace("iso639-2: ", string.Empty).Trim();
63                 }
64 
65                 return string.Empty;
66             }
67         }
68 
69         public bool CanBurnIn { get; private set; }
70 
71         public bool CanForce { get; private set; }
72 
73         public SubtitleType SubtitleType { get; set; }
74 
75         public string Name { get; set; }
76 
77         public bool IsFakeForeignAudioScanTrack { get; set; }
78 
79         public string TypeString
80         {
81             get
82             {
83                 return EnumHelper<Enum>.GetDescription(this.SubtitleType);
84             }
85         }
86 
ToString()87         public override string ToString()
88         {
89             return this.IsFakeForeignAudioScanTrack ? Resources.Subtitle_ForeignAudioScan : string.Format("{0} {1}", this.TrackNumber, this.Language);
90         }
91 
Equals(Subtitle other)92         public bool Equals(Subtitle other)
93         {
94             if (ReferenceEquals(null, other))
95             {
96                 return false;
97             }
98 
99             if (ReferenceEquals(this, other))
100             {
101                 return true;
102             }
103 
104             return other.TrackNumber == this.TrackNumber && object.Equals(other.Language, this.Language) && object.Equals(other.LanguageCode, this.LanguageCode) && object.Equals(other.SubtitleType, this.SubtitleType);
105         }
106 
Equals(object obj)107         public override bool Equals(object obj)
108         {
109             if (ReferenceEquals(null, obj))
110             {
111                 return false;
112             }
113 
114             if (ReferenceEquals(this, obj))
115             {
116                 return true;
117             }
118 
119             if (obj.GetType() != typeof(Subtitle))
120             {
121                 return false;
122             }
123 
124             return this.Equals((Subtitle)obj);
125         }
126 
GetHashCode()127         public override int GetHashCode()
128         {
129             unchecked
130             {
131                 int result = this.TrackNumber;
132                 result = (result * 397) ^ (this.Language != null ? this.Language.GetHashCode() : 0);
133                 result = (result * 397) ^ (this.LanguageCode != null ? this.LanguageCode.GetHashCode() : 0);
134                 result = (result * 397) ^ this.SubtitleType.GetHashCode();
135                 return result;
136             }
137         }
138     }
139 }
140