First public contribution.
2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include <banamedplugins.h>
24 #include <convnames.h>
27 _LIT(KLitNameOfResourceFileForBuiltInCharacterSets, "z:\\resource\\charconv\\BUILTIN.RSC");
28 _LIT(KLitRscExtension, ".RSC");
31 // CCnvCharacterSetNames
33 EXPORT_C CCnvCharacterSetNames* CCnvCharacterSetNames::NewL(RFs& aFileServerSession, const TArray<CCnvCharacterSetConverter::SCharacterSet>& aArrayOfCharacterSetsAvailable)
34 /** Allocates and constructs a localised list of character set encoding names.
36 @param aFileServerSession A connected session with the file server.
37 @param aArrayOfCharacterSetsAvailable The array of character sets available
38 on the phone. This can be created using CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableL()
39 or CreateArrayOfCharacterSetsAvailableLC().
40 @return Pointer to the newly created object. */
42 CCnvCharacterSetNames* arrayOfNamedCharacterSets=NewLC(aFileServerSession, aArrayOfCharacterSetsAvailable);
43 CleanupStack::Pop(arrayOfNamedCharacterSets);
44 return arrayOfNamedCharacterSets;
48 EXPORT_C CCnvCharacterSetNames* CCnvCharacterSetNames::NewLC(RFs& aFileServerSession, const TArray<CCnvCharacterSetConverter::SCharacterSet>& aArrayOfCharacterSetsAvailable)
49 /** Allocates and constructs a localised list of character set encoding names.
50 Puts a pointer to the object on the cleanup stack.
52 @param aFileServerSession A connected session with the file server.
53 @param aArrayOfCharacterSetsAvailable The array of character sets available
54 on the phone. This can be created using CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableL()
55 or CreateArrayOfCharacterSetsAvailableLC().
56 @return Pointer to the newly created object. */
58 CCnvCharacterSetNames* arrayOfNamedCharacterSets=new(ELeave) CCnvCharacterSetNames;
59 CleanupStack::PushL(arrayOfNamedCharacterSets);
60 arrayOfNamedCharacterSets->ConstructL(aFileServerSession, aArrayOfCharacterSetsAvailable);
61 return arrayOfNamedCharacterSets;
64 EXPORT_C CCnvCharacterSetNames::~CCnvCharacterSetNames()
65 /** Deletes the array of named plug-ins owned by the object prior to its destruction. */
71 EXPORT_C TInt CCnvCharacterSetNames::IndexOfIdentifier(TUint aIdentifier) const
72 /** Gets the index into the sorted list of the character set identifier specified.
74 @param aIdentifier The character set identifier. This must not be zero, or
76 @return The index into the list of the character set identifier, or KErrNotFound
77 if the identifier does not exist in the list. */
79 return iNamedPlugins->IndexOfUid(TUid::Uid(aIdentifier));
83 EXPORT_C TUint CCnvCharacterSetNames::IdentifierAtIndex(TInt aIndex) const
84 /** Gets the character set identifier at the specified index into the list.
86 @param aIndex The index into the list. Must be within the bounds of the array,
88 @return The character set identifier at the specified index. */
90 return iNamedPlugins->UidAtIndex(aIndex).iUid;
93 CCnvCharacterSetNames::CCnvCharacterSetNames()
98 void CCnvCharacterSetNames::DestroyResourceFileArray(TAny* aArrayOfCharconvResourceFiles)
100 RArray<CBaNamedPlugins::TResourceFile>& arrayOfCharconvResourceFiles=*STATIC_CAST(RArray<CBaNamedPlugins::TResourceFile>*, aArrayOfCharconvResourceFiles);
101 for (TInt i=arrayOfCharconvResourceFiles.Count()-1; i>=0; --i)
103 const CBaNamedPlugins::TResourceFile& resourceFile=arrayOfCharconvResourceFiles[i];
104 delete resourceFile.iFullFileName;
105 delete resourceFile.iIdentifier;
107 arrayOfCharconvResourceFiles.Close();
110 void CCnvCharacterSetNames::ConstructL(RFs& aFileServerSession, const TArray<CCnvCharacterSetConverter::SCharacterSet>& aArrayOfCharacterSetsAvailable)
112 RArray<CBaNamedPlugins::TResourceFile> arrayOfCharconvResourceFiles;
113 CleanupStack::PushL(TCleanupItem(DestroyResourceFileArray, &arrayOfCharconvResourceFiles));
114 TParse* parser=new(ELeave) TParse;
115 CleanupStack::PushL(parser);
116 CBaNamedPlugins::TResourceFile resourceFile;
117 resourceFile.iFullFileName=KLitNameOfResourceFileForBuiltInCharacterSets().AllocLC();
118 resourceFile.iIdentifier=NULL;
119 resourceFile.iUid=KNullUid;
120 resourceFile.iFormat=CBaNamedPlugins::TResourceFile::EFormatArrayOfUidNamePairs;
121 User::LeaveIfError(arrayOfCharconvResourceFiles.Append(resourceFile));
122 CleanupStack::Pop(resourceFile.iFullFileName);
123 for (TInt i=aArrayOfCharacterSetsAvailable.Count()-1; i>=0; --i)
125 const CCnvCharacterSetConverter::SCharacterSet& characterSet=aArrayOfCharacterSetsAvailable[i];
126 if (characterSet.NameIsFileName())
128 const TPtrC fileNameOfCharacterSetPlugIn(characterSet.Name());
129 User::LeaveIfError(parser->SetNoWild(KLitRscExtension, &fileNameOfCharacterSetPlugIn, NULL));
130 CBaNamedPlugins::TResourceFile resourceFile;
131 resourceFile.iFullFileName=parser->FullName().AllocLC();
132 resourceFile.iIdentifier=NULL;
133 resourceFile.iUid=TUid::Uid(characterSet.Identifier());
134 resourceFile.iFormat=CBaNamedPlugins::TResourceFile::EFormatTbuf;
135 User::LeaveIfError(arrayOfCharconvResourceFiles.Append(resourceFile));
136 CleanupStack::Pop(resourceFile.iFullFileName);
139 CleanupStack::PopAndDestroy(parser);
140 CBaNamedPlugins::CParameters* const parameters=CBaNamedPlugins::CParameters::NewLC(aFileServerSession, arrayOfCharconvResourceFiles.Array());
141 iNamedPlugins=CBaNamedPlugins::NewL(*parameters);
142 CleanupStack::PopAndDestroy(2, &arrayOfCharconvResourceFiles);
145 TInt CCnvCharacterSetNames::MdcaCount() const
147 return iNamedPlugins->MdcaCount();
150 TPtrC CCnvCharacterSetNames::MdcaPoint(TInt aIndex) const
152 return iNamedPlugins->MdcaPoint(aIndex);