2 * This file is part of SubLib.
3 * Copyright (C) 2006-2008,2011 Pedro Castro
5 * SubLib is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * SubLib is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 using SubLib
.IO
.SubtitleFormats
;
23 namespace SubLib
.Core
.Domain
{
25 /// <summary>Contains information about a subtitle file type.</summary>
26 public class SubtitleTypeInfo
: IComparable
{
28 private SubtitleType type
;
29 private SubtitleMode mode
;
30 private string[] extensions
;
33 /// <summary>Initializes a new instance of the <see cref="SubtitleTypeInfo" /> class.</summary>
34 /// <param name="name">The name of the subtitle type.</param>
35 /// <param name="type">The subtitle type.</param>
36 /// <param name="mode">The subtitle mode.</param>
37 /// <param name="extensions">The extensions the subtitle type uses.</param>
38 public SubtitleTypeInfo (string name
, SubtitleType type
, SubtitleMode mode
, string[] extensions
) {
42 this.extensions
= extensions
;
45 /// <summary>The name of the subtitle type.</summary>
50 /// <summary>The subtitle type.</summary>
51 public SubtitleType Type
{
55 /// <summary>The subtitle mode.</summary>
56 public SubtitleMode Mode
{
60 /// <summary>The extensions the subtitle type uses.</summary>
61 public string[] Extensions
{
62 get { return extensions; }
65 /// <summary>A comma-separated list of the extensions the subtitle type uses.
66 /// The prefix "*." is added to every extension.</summary>
67 public string ExtensionsAsText
{
68 get { return ExtensionsToText(); }
71 /// <summary>The preferred extension, which is the first on the list.</summary>
72 public string PreferredExtension
{
73 get { return extensions[0]; }
76 /// <summary>Checks whether the specified extension is one of the extensions of the <see cref="SubtitleType" /></summary>
77 /// <param name="extension">The extension to search for.</param>
78 /// <returns>True if the extension was found, False otherwise.</returns>
79 public bool HasExtension (string extension
) {
80 foreach (string typeExtension
in extensions
) {
81 if (typeExtension
== extension
)
87 /// <summary>Compares this instance with a specified object, based on the object names.
88 /// See <see cref="String.CompareTo(object)" /> for more information.</summary>
89 /// <param name="obj">The object to compare this class to.</param>
91 /// <list type="table">
92 /// <listheader><term>Value</term><description>Condition</description></listheader>
93 /// <item><term>Less than zero</term><description>This instance is less than obj.</description></item>
94 /// <item><term>Zero</term><description>This instance is equal to obj.</description></item>
95 /// <item><term>Greater than zero</term><description>This instance is greater than obj, or obj is a
96 /// null reference.</description></item>
99 public int CompareTo (object obj
) {
100 return Name
.CompareTo((obj
as SubtitleTypeInfo
).Name
);
103 /* Internal members */
105 internal SubtitleTypeInfo (SubtitleFormat format
) : this(format
.Name
, format
.Type
, format
.Mode
, format
.Extensions
) {
108 /* Private members */
110 private string ExtensionsToText () {
111 if (extensions
== null)
114 string text
= ExtensionToText(extensions
[0]);
115 for (int count
= 1 ; count
< extensions
.Length
; count
++)
116 text
+= ", " + ExtensionToText(extensions
[count
]);
121 private string ExtensionToText (string extension
) {
122 return "*." + extension
;