os/textandloc/charconvfw/charconv_fw/src/convnames/convnames.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <e32std.h>
sl@0
    20
#include <e32base.h>
sl@0
    21
#include <f32file.h>
sl@0
    22
#include <banamedplugins.h>
sl@0
    23
#include <charconv.h>
sl@0
    24
#include <convnames.h>
sl@0
    25
sl@0
    26
sl@0
    27
_LIT(KLitNameOfResourceFileForBuiltInCharacterSets, "z:\\resource\\charconv\\BUILTIN.RSC");
sl@0
    28
_LIT(KLitRscExtension, ".RSC");
sl@0
    29
sl@0
    30
sl@0
    31
// CCnvCharacterSetNames
sl@0
    32
sl@0
    33
EXPORT_C CCnvCharacterSetNames* CCnvCharacterSetNames::NewL(RFs& aFileServerSession, const TArray<CCnvCharacterSetConverter::SCharacterSet>& aArrayOfCharacterSetsAvailable)
sl@0
    34
/** Allocates and constructs a localised list of character set encoding names.
sl@0
    35
sl@0
    36
@param aFileServerSession A connected session with the file server.
sl@0
    37
@param aArrayOfCharacterSetsAvailable The array of character sets available 
sl@0
    38
on the phone. This can be created using CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableL() 
sl@0
    39
or CreateArrayOfCharacterSetsAvailableLC().
sl@0
    40
@return Pointer to the newly created object. */
sl@0
    41
	{
sl@0
    42
	CCnvCharacterSetNames* arrayOfNamedCharacterSets=NewLC(aFileServerSession, aArrayOfCharacterSetsAvailable);
sl@0
    43
	CleanupStack::Pop(arrayOfNamedCharacterSets);
sl@0
    44
	return arrayOfNamedCharacterSets;
sl@0
    45
	}
sl@0
    46
sl@0
    47
sl@0
    48
EXPORT_C CCnvCharacterSetNames* CCnvCharacterSetNames::NewLC(RFs& aFileServerSession, const TArray<CCnvCharacterSetConverter::SCharacterSet>& aArrayOfCharacterSetsAvailable)
sl@0
    49
/** Allocates and constructs a localised list of character set encoding names. 
sl@0
    50
Puts a pointer to the object on the cleanup stack.
sl@0
    51
sl@0
    52
@param aFileServerSession A connected session with the file server.
sl@0
    53
@param aArrayOfCharacterSetsAvailable The array of character sets available 
sl@0
    54
on the phone. This can be created using CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableL() 
sl@0
    55
or CreateArrayOfCharacterSetsAvailableLC().
sl@0
    56
@return Pointer to the newly created object. */
sl@0
    57
	{
sl@0
    58
	CCnvCharacterSetNames* arrayOfNamedCharacterSets=new(ELeave) CCnvCharacterSetNames;
sl@0
    59
	CleanupStack::PushL(arrayOfNamedCharacterSets);
sl@0
    60
	arrayOfNamedCharacterSets->ConstructL(aFileServerSession, aArrayOfCharacterSetsAvailable);
sl@0
    61
	return arrayOfNamedCharacterSets;
sl@0
    62
	}
sl@0
    63
sl@0
    64
EXPORT_C CCnvCharacterSetNames::~CCnvCharacterSetNames()
sl@0
    65
/** Deletes the array of named plug-ins owned by the object prior to its destruction. */
sl@0
    66
	{
sl@0
    67
	delete iNamedPlugins;
sl@0
    68
	}
sl@0
    69
sl@0
    70
sl@0
    71
EXPORT_C TInt CCnvCharacterSetNames::IndexOfIdentifier(TUint aIdentifier) const
sl@0
    72
/** Gets the index into the sorted list of the character set identifier specified. 
sl@0
    73
sl@0
    74
@param aIdentifier The character set identifier. This must not be zero, or 
sl@0
    75
a panic occurs.
sl@0
    76
@return The index into the list of the character set identifier, or KErrNotFound 
sl@0
    77
if the identifier does not exist in the list. */
sl@0
    78
	{
sl@0
    79
	return iNamedPlugins->IndexOfUid(TUid::Uid(aIdentifier));
sl@0
    80
	}
sl@0
    81
sl@0
    82
sl@0
    83
EXPORT_C TUint CCnvCharacterSetNames::IdentifierAtIndex(TInt aIndex) const
sl@0
    84
/** Gets the character set identifier at the specified index into the list.
sl@0
    85
sl@0
    86
@param aIndex The index into the list. Must be within the bounds of the array, 
sl@0
    87
or a panic occurs.
sl@0
    88
@return The character set identifier at the specified index. */
sl@0
    89
	{
sl@0
    90
	return iNamedPlugins->UidAtIndex(aIndex).iUid;
sl@0
    91
	}
sl@0
    92
sl@0
    93
CCnvCharacterSetNames::CCnvCharacterSetNames()
sl@0
    94
	:iNamedPlugins(NULL)
sl@0
    95
	{
sl@0
    96
	}
sl@0
    97
sl@0
    98
void CCnvCharacterSetNames::DestroyResourceFileArray(TAny* aArrayOfCharconvResourceFiles)
sl@0
    99
	{
sl@0
   100
	RArray<CBaNamedPlugins::TResourceFile>& arrayOfCharconvResourceFiles=*STATIC_CAST(RArray<CBaNamedPlugins::TResourceFile>*, aArrayOfCharconvResourceFiles);
sl@0
   101
	for (TInt i=arrayOfCharconvResourceFiles.Count()-1; i>=0; --i)
sl@0
   102
		{
sl@0
   103
		const CBaNamedPlugins::TResourceFile& resourceFile=arrayOfCharconvResourceFiles[i];
sl@0
   104
		delete resourceFile.iFullFileName;
sl@0
   105
		delete resourceFile.iIdentifier;
sl@0
   106
		}
sl@0
   107
	arrayOfCharconvResourceFiles.Close();
sl@0
   108
	}
sl@0
   109
sl@0
   110
void CCnvCharacterSetNames::ConstructL(RFs& aFileServerSession, const TArray<CCnvCharacterSetConverter::SCharacterSet>& aArrayOfCharacterSetsAvailable)
sl@0
   111
	{
sl@0
   112
	RArray<CBaNamedPlugins::TResourceFile> arrayOfCharconvResourceFiles;
sl@0
   113
	CleanupStack::PushL(TCleanupItem(DestroyResourceFileArray, &arrayOfCharconvResourceFiles));
sl@0
   114
	TParse* parser=new(ELeave) TParse;
sl@0
   115
	CleanupStack::PushL(parser);
sl@0
   116
	CBaNamedPlugins::TResourceFile resourceFile;
sl@0
   117
	resourceFile.iFullFileName=KLitNameOfResourceFileForBuiltInCharacterSets().AllocLC();
sl@0
   118
	resourceFile.iIdentifier=NULL;
sl@0
   119
	resourceFile.iUid=KNullUid;
sl@0
   120
	resourceFile.iFormat=CBaNamedPlugins::TResourceFile::EFormatArrayOfUidNamePairs;
sl@0
   121
	User::LeaveIfError(arrayOfCharconvResourceFiles.Append(resourceFile));
sl@0
   122
	CleanupStack::Pop(resourceFile.iFullFileName);
sl@0
   123
	for (TInt i=aArrayOfCharacterSetsAvailable.Count()-1; i>=0; --i)
sl@0
   124
		{
sl@0
   125
		const CCnvCharacterSetConverter::SCharacterSet& characterSet=aArrayOfCharacterSetsAvailable[i];
sl@0
   126
		if (characterSet.NameIsFileName())
sl@0
   127
			{
sl@0
   128
			const TPtrC fileNameOfCharacterSetPlugIn(characterSet.Name());
sl@0
   129
			User::LeaveIfError(parser->SetNoWild(KLitRscExtension, &fileNameOfCharacterSetPlugIn, NULL));
sl@0
   130
			CBaNamedPlugins::TResourceFile resourceFile;
sl@0
   131
			resourceFile.iFullFileName=parser->FullName().AllocLC();
sl@0
   132
			resourceFile.iIdentifier=NULL;
sl@0
   133
			resourceFile.iUid=TUid::Uid(characterSet.Identifier());
sl@0
   134
			resourceFile.iFormat=CBaNamedPlugins::TResourceFile::EFormatTbuf;
sl@0
   135
			User::LeaveIfError(arrayOfCharconvResourceFiles.Append(resourceFile));
sl@0
   136
			CleanupStack::Pop(resourceFile.iFullFileName);
sl@0
   137
			}
sl@0
   138
		}
sl@0
   139
	CleanupStack::PopAndDestroy(parser);
sl@0
   140
	CBaNamedPlugins::CParameters* const parameters=CBaNamedPlugins::CParameters::NewLC(aFileServerSession, arrayOfCharconvResourceFiles.Array());
sl@0
   141
	iNamedPlugins=CBaNamedPlugins::NewL(*parameters);
sl@0
   142
	CleanupStack::PopAndDestroy(2, &arrayOfCharconvResourceFiles);
sl@0
   143
	}
sl@0
   144
sl@0
   145
TInt CCnvCharacterSetNames::MdcaCount() const
sl@0
   146
	{
sl@0
   147
	return iNamedPlugins->MdcaCount();
sl@0
   148
	}
sl@0
   149
sl@0
   150
TPtrC CCnvCharacterSetNames::MdcaPoint(TInt aIndex) const
sl@0
   151
	{
sl@0
   152
	return iNamedPlugins->MdcaPoint(aIndex);
sl@0
   153
	}
sl@0
   154