|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <f32file.h> |
|
17 #include <e32uid.h> |
|
18 #include <s32file.h> |
|
19 #include "B64CONV.H" |
|
20 #include "TXCONV.H" |
|
21 #include "QPCONV.H" |
|
22 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
23 #include "coninternal.h" |
|
24 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
25 #include "CONLIST.H" |
|
26 #include "CONSTD.H" |
|
27 |
|
28 const TInt KConverterListGranularity=5; |
|
29 |
|
30 // |
|
31 // class CCnaConverterList |
|
32 // |
|
33 |
|
34 EXPORT_C CCnaConverterList* CCnaConverterList::NewL() |
|
35 /** Allocates and constructs a CCnaConverterList. |
|
36 |
|
37 @return New converter list */ |
|
38 { |
|
39 CCnaConverterList* self=CCnaConverterList::NewLC(); |
|
40 CleanupStack::Pop(); // self |
|
41 return self; |
|
42 } |
|
43 |
|
44 EXPORT_C CCnaConverterList* CCnaConverterList::NewLC() |
|
45 /** Allocates and constructs a CCnaConverterList, leaving the object on the cleanup |
|
46 stack. |
|
47 |
|
48 @return New converter list */ |
|
49 { |
|
50 CCnaConverterList* self=new(ELeave) CCnaConverterList(); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 CCnaConverterList::CCnaConverterList() |
|
57 { |
|
58 __DECLARE_NAME(_S("CCnaConverterList")); |
|
59 } |
|
60 |
|
61 void CCnaConverterList::ConstructL() |
|
62 { |
|
63 iConverters=new(ELeave) CArrayPtrFlat<CCnaConverter>(KConverterListGranularity); |
|
64 } |
|
65 |
|
66 EXPORT_C CCnaConverterList::~CCnaConverterList() |
|
67 /** Destructor. |
|
68 |
|
69 This releases all loaded converter DLLs. */ |
|
70 { |
|
71 if (iConverters) |
|
72 { |
|
73 iConverters->ResetAndDestroy(); |
|
74 delete iConverters; |
|
75 } |
|
76 iImplementationArray.ResetAndDestroy(); |
|
77 } |
|
78 |
|
79 EXPORT_C void CCnaConverterList::Release() |
|
80 /** Legacy function, do not use. */ |
|
81 { |
|
82 } |
|
83 |
|
84 EXPORT_C TInt CCnaConverterList::CountL() |
|
85 /** Gets the total number of converters. |
|
86 |
|
87 It can leave because it needs to rescan the disk to refresh |
|
88 the list of converters. |
|
89 |
|
90 @return Total number of converters */ |
|
91 { |
|
92 if (!iDoneScan) |
|
93 UpdateL(); |
|
94 TInt count=0; |
|
95 return count+iImplementationArray.Count(); |
|
96 } |
|
97 |
|
98 EXPORT_C CConverterBase* CCnaConverterList::NewConverterL(TUid aUid) |
|
99 /** Locates the converter with the specified UID, loads its associated DLL |
|
100 and returns a pointer to it. |
|
101 |
|
102 @param aUid Converter UID |
|
103 @return Converter with the specified UID, or NULL if there is no suitable converter */ |
|
104 { |
|
105 CConverterBase* base=ConverterListUtil::UtilityConverterL(aUid); |
|
106 if (base) |
|
107 return base; |
|
108 if (!iDoneScan) |
|
109 UpdateL(); |
|
110 TInt i; |
|
111 TInt count; |
|
112 count = iImplementationArray.Count(); |
|
113 for (i = 0; i < count; i++) |
|
114 { |
|
115 if (iImplementationArray[i]->ImplementationUid()==aUid) |
|
116 { |
|
117 return LoadConverterL(iImplementationArray[i]->ImplementationUid()); |
|
118 } |
|
119 } |
|
120 return NULL; |
|
121 } |
|
122 |
|
123 EXPORT_C void CCnaConverterList::UpdateL() |
|
124 /** Requests a rescan of the disk to refresh the list of converters. */ |
|
125 { |
|
126 // delete old array and populate it with new values |
|
127 iImplementationArray.ResetAndDestroy(); |
|
128 REComSession::ListImplementationsL(KUidConverterDll16,iImplementationArray); |
|
129 for (TInt i=0; i<iImplementationArray.Count(); i++) |
|
130 {// load the conarc-plugin resource file. This should be set to 1 in |
|
131 // the ecom resource file to show there is extra file to load |
|
132 if (iImplementationArray[i]->OpaqueData().Length()!=0 ) |
|
133 { |
|
134 _LIT(KPath,"z:\\resource\\convert\\"); |
|
135 _LIT(KExtension,".rsc"); |
|
136 TFileName resourceFile; |
|
137 resourceFile.Copy(KPath); |
|
138 resourceFile.AppendNum((TInt)iImplementationArray[i]->ImplementationUid().iUid, EHex); |
|
139 resourceFile.Append(KExtension); |
|
140 CCnaConvInfoFileReader2* readConverter=CCnaConvInfoFileReader2::NewL(resourceFile); |
|
141 CleanupStack::PushL(readConverter); |
|
142 readConverter->RestoreL(); |
|
143 const TInt converterCount = readConverter->Count(); |
|
144 for (TInt j = 0 ; j < converterCount ; j++ ) |
|
145 { |
|
146 CCnaConverter* tempConv= readConverter->AtL(j); |
|
147 CleanupStack::PushL(tempConv); |
|
148 iConverters->AppendL(tempConv); |
|
149 CleanupStack::Pop(tempConv); |
|
150 } |
|
151 CleanupStack::PopAndDestroy(readConverter); |
|
152 } |
|
153 } |
|
154 iDoneScan=ETrue; |
|
155 } |
|
156 |
|
157 EXPORT_C TUid CCnaConverterList::ConvFromL(const TDataType& aMimeType) |
|
158 // searches for a particular converter that converts from the specified Mime Type |
|
159 // |
|
160 // To be called iteratively to find all available converters |
|
161 // for the specified mime type |
|
162 // |
|
163 // returns the Uid of the converter or NULL when no converters remain |
|
164 /** Gets the UID of the converter that converts from the specified data type. |
|
165 |
|
166 @param aMimeType Source data type |
|
167 @return Converter UID */ |
|
168 { |
|
169 TInt i; |
|
170 TInt count=iConverters->Count(); |
|
171 for (i=0; i < count; i++) |
|
172 { |
|
173 CCnaConverter* converter = iConverters->At(i); |
|
174 if (converter->MimeFrom(aMimeType)) |
|
175 { |
|
176 return converter->Uid(); |
|
177 } |
|
178 } |
|
179 return KNullUid; |
|
180 } |
|
181 |
|
182 EXPORT_C TUid CCnaConverterList::ConvToL(const TDataType& aMimeType) |
|
183 // searches for a particular converter that converts to the specified Mime Type |
|
184 // as for GetConvFromL() but specifing a target mime type |
|
185 /** Gets the UID of the converter that converts to a specified data type. |
|
186 |
|
187 @param aMimeType Target data type |
|
188 @return Converter UID */ |
|
189 { |
|
190 TInt i; |
|
191 TInt count=iConverters->Count(); |
|
192 for (i=0; i < count; i++) |
|
193 { |
|
194 CCnaConverter* converter = iConverters->At(i); |
|
195 if (converter->MimeTo(aMimeType)) |
|
196 { |
|
197 return converter->Uid(); |
|
198 } |
|
199 } |
|
200 return KNullUid; |
|
201 } |
|
202 |
|
203 EXPORT_C TUid CCnaConverterList::ConverterL(const TDataType& aFrom,const TDataType& aTo) |
|
204 /** Gets the UID of the converter that converts to and from the specified data types. |
|
205 |
|
206 @param aFrom Source data type |
|
207 @param aTo Target data type |
|
208 @return Converter UID */ |
|
209 { |
|
210 if (!iDoneScan) |
|
211 UpdateL(); |
|
212 TInt ii; |
|
213 TInt count=iConverters->Count(); |
|
214 for (ii=0;ii<count;ii++) |
|
215 { |
|
216 const CCnaConverter* conv=iConverters->At(ii); |
|
217 if (conv->MimeFrom(aFrom) && conv->MimeTo(aTo)) |
|
218 { |
|
219 return conv->Uid(); |
|
220 } |
|
221 } |
|
222 return KNullUid; |
|
223 } |
|
224 |
|
225 |
|
226 // Compiles a list of converters that convert FROM a mime type. |
|
227 // Produces an array of the translations of the types they convert FROM |
|
228 // and a corresponding array of uids. |
|
229 // The data type to convert TO is supplied |
|
230 |
|
231 EXPORT_C void CCnaConverterList::ConvFromListL(const TDataType& aMimeType,CArrayFix<SConverterInfo>* aSConverterInfoArray) |
|
232 /** Gets a list of converters that convert from a specified data type. |
|
233 |
|
234 @param aMimeType Source data type |
|
235 @param aSConverterInfoArray On return, array of converter information objects |
|
236 for all suitable converters */ |
|
237 { |
|
238 ASSERT(aSConverterInfoArray->Count()==0); |
|
239 if (!iDoneScan) |
|
240 UpdateL(); |
|
241 |
|
242 TInt i; |
|
243 TInt count = iConverters->Count(); |
|
244 for (i = 0; i < count; i++) |
|
245 { |
|
246 CCnaConverter* conv = iConverters->At(i); |
|
247 //does converter support this type |
|
248 if (conv->MimeFrom(aMimeType) ) |
|
249 { |
|
250 const TInt countTo = conv->CountTo(); |
|
251 //add the types that it converts to |
|
252 for( TInt j=0;j<countTo;j++) |
|
253 { |
|
254 SConverterInfo info; |
|
255 info.iTranslation=conv->MimeToText(j); |
|
256 info.iUid=conv->Uid(); |
|
257 info.iIndex=j; |
|
258 aSConverterInfoArray->AppendL(info); |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 } |
|
264 |
|
265 // Compiles a list of converters that convert TO a mime type. |
|
266 // Produces an array of the translations of the types they convert TO |
|
267 // and a corresponding array of uids. |
|
268 // The data type to convert FROM is supplied |
|
269 |
|
270 EXPORT_C void CCnaConverterList::ConvToListL(const TDataType& aMimeType,CArrayFix<SConverterInfo>* aSConverterInfoArray) |
|
271 /** Gets a list of converters that convert to a specified data type. |
|
272 |
|
273 @param aMimeType Target data type |
|
274 @param aSConverterInfoArray On return, an array of converter information objects |
|
275 for all suitable converters */ |
|
276 { |
|
277 ASSERT(aSConverterInfoArray->Count()==0); |
|
278 if (!iDoneScan) |
|
279 UpdateL(); |
|
280 TInt i; |
|
281 TInt count = iConverters->Count(); |
|
282 for (i = 0; i < count; i++) |
|
283 { |
|
284 CCnaConverter* conv = iConverters->At(i); |
|
285 //does converter support this type |
|
286 if (conv->MimeTo(aMimeType) ) |
|
287 { |
|
288 const TInt countFrom=conv->CountFrom(); |
|
289 for( TInt j=0;j<countFrom;j++) |
|
290 { |
|
291 SConverterInfo info; |
|
292 info.iTranslation=conv->MimeFromText(j); |
|
293 info.iUid=conv->Uid(); |
|
294 info.iIndex=j; |
|
295 aSConverterInfoArray->AppendL(info); |
|
296 } |
|
297 } |
|
298 } |
|
299 } |
|
300 |
|
301 EXPORT_C TInt CCnaConverterList::MimeTypeFrom(TDataType& aDataType,const SConverterInfo& aInfo) const |
|
302 /** Gets converter information for a specified source data type. |
|
303 |
|
304 @param aDataType Source data type |
|
305 @param aConverterInfo On return, converter information for a suitable converter |
|
306 @return KErrNone if a suitable converter was found, else KErrNotFound */ |
|
307 { |
|
308 TInt i; |
|
309 TInt count = iConverters->Count(); |
|
310 for (i = 0; i < count; i++) |
|
311 { |
|
312 const CCnaConverter* conv = iConverters->At(i); |
|
313 if (conv->Uid()==aInfo.iUid) |
|
314 { |
|
315 if((aInfo.iIndex>=0) && (aInfo.iIndex<conv->CountFrom())) |
|
316 { |
|
317 aDataType=conv->MimeFrom(aInfo.iIndex); |
|
318 return KErrNone; |
|
319 } |
|
320 break; |
|
321 } |
|
322 } |
|
323 return KErrNotFound; |
|
324 } |
|
325 |
|
326 EXPORT_C TInt CCnaConverterList::MimeTypeTo(TDataType& aDataType,const SConverterInfo& aInfo) const |
|
327 /** Gets converter information for a specified target data type. |
|
328 |
|
329 @param aDataType Target data type |
|
330 @param aConverterInfo On return, converter information for a suitable converter |
|
331 @return KErrNone if a suitable converter was found, else KErrNotFound */ |
|
332 { |
|
333 TInt i; |
|
334 TInt count = iConverters->Count(); |
|
335 for (i = 0; i < count; i++) |
|
336 { |
|
337 const CCnaConverter* conv = iConverters->At(i); |
|
338 if (conv->Uid()==aInfo.iUid) |
|
339 { |
|
340 if(aInfo.iIndex>=0 && aInfo.iIndex<conv->CountTo()) |
|
341 { |
|
342 aDataType=conv->MimeTo(aInfo.iIndex); |
|
343 return KErrNone; |
|
344 } |
|
345 break; |
|
346 } |
|
347 } |
|
348 return KErrNotFound; |
|
349 } |
|
350 |
|
351 CConverterBase* CCnaConverterList::LoadConverterL(TUid aImplUid) |
|
352 { |
|
353 return CConverterBase2::CreateConverterL(aImplUid); |
|
354 } |
|
355 |
|
356 CConverterBase* ConverterListUtil::UtilityConverterL(TUid aUid) |
|
357 { |
|
358 switch (aUid.iUid) |
|
359 { |
|
360 case KBase64Decoder: |
|
361 return new(ELeave) CBase64Decoder(); |
|
362 case KBase64Encoder: |
|
363 return new(ELeave) CBase64Encoder(); |
|
364 case KQuotedPrintableToText: |
|
365 return new(ELeave) CQpToTxtCnv(); |
|
366 case KTextToQuotedPrintable: |
|
367 return new(ELeave) CTxtToQpCnv(); |
|
368 case KEtextToText: |
|
369 return new(ELeave) CEtToTxtCnv(); |
|
370 case KTextToEtext: |
|
371 return new(ELeave) CTxtToEtCnv(); |
|
372 case KTextToEtextNoTrim: |
|
373 return new(ELeave) CTxtToEtCnv(ETrue); |
|
374 default: |
|
375 return NULL; |
|
376 } |
|
377 } |
|
378 |
|
379 TInt ConverterListUtil::CountUtilityConverters() |
|
380 { |
|
381 return 6; |
|
382 } |