|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.IO; |
|
19 using System.Collections.Generic; |
|
20 using System.Text; |
|
21 using SymbianUtils; |
|
22 |
|
23 namespace SymbianUtils.FileTypes |
|
24 { |
|
25 public class SymFileTypeList : IEnumerable<SymFileType> |
|
26 { |
|
27 #region Constructors |
|
28 public SymFileTypeList() |
|
29 { |
|
30 } |
|
31 #endregion |
|
32 |
|
33 #region API |
|
34 public void Clear() |
|
35 { |
|
36 iTypes.Clear(); |
|
37 } |
|
38 |
|
39 public void Add( SymFileType aType ) |
|
40 { |
|
41 if ( !iTypes.ContainsKey( aType.Extension ) ) |
|
42 { |
|
43 iTypes.Add( aType.Extension.ToUpper(), aType ); |
|
44 } |
|
45 } |
|
46 |
|
47 public void AddRange( IEnumerable<SymFileType> aTypes ) |
|
48 { |
|
49 foreach ( SymFileType type in aTypes ) |
|
50 { |
|
51 Add( type ); |
|
52 } |
|
53 } |
|
54 |
|
55 public bool IsSupported( string aFileName ) |
|
56 { |
|
57 string ext = Path.GetExtension( aFileName ); |
|
58 bool ret = iTypes.ContainsKey( ext.ToUpper() ); |
|
59 return ret; |
|
60 } |
|
61 #endregion |
|
62 |
|
63 #region Properties |
|
64 public int Count |
|
65 { |
|
66 get { return iTypes.Count; } |
|
67 } |
|
68 #endregion |
|
69 |
|
70 #region From System.Object |
|
71 public override string ToString() |
|
72 { |
|
73 // Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.* |
|
74 StringBuilder ret = new StringBuilder(); |
|
75 // |
|
76 foreach ( KeyValuePair<string, SymFileType> kvp in iTypes ) |
|
77 { |
|
78 string extension = kvp.Value.ToString(); |
|
79 ret.Append( "|" ); |
|
80 } |
|
81 |
|
82 // Remove last | if present |
|
83 int length = ret.Length; |
|
84 if ( length > 0 ) |
|
85 { |
|
86 if ( ret[ length - 1 ] == '|' ) |
|
87 { |
|
88 ret.Length = length - 1; |
|
89 } |
|
90 } |
|
91 // |
|
92 return ret.ToString(); |
|
93 } |
|
94 #endregion |
|
95 |
|
96 #region From IEnumerable<SymFileType> |
|
97 public IEnumerator<SymFileType> GetEnumerator() |
|
98 { |
|
99 foreach ( KeyValuePair<string,SymFileType> type in iTypes ) |
|
100 { |
|
101 yield return type.Value; |
|
102 } |
|
103 } |
|
104 |
|
105 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
106 { |
|
107 foreach ( KeyValuePair<string, SymFileType> type in iTypes ) |
|
108 { |
|
109 yield return type.Value; |
|
110 } |
|
111 } |
|
112 #endregion |
|
113 |
|
114 #region Data members |
|
115 private Dictionary<string, SymFileType> iTypes = new Dictionary<string, SymFileType>(); |
|
116 #endregion |
|
117 } |
|
118 } |