pimappsupport/vcardandvcal/inc/VUTIL.H
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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 #ifndef __VUTIL_H__
       
    17 #define __VUTIL_H__
       
    18 
       
    19 // System includes
       
    20 #ifndef __E32BASE_H__
       
    21 #include <e32base.h>
       
    22 #endif
       
    23 #ifndef __F32FILE_H__
       
    24 #include <f32file.h>
       
    25 #endif
       
    26 #ifndef __CHARCONV_H__
       
    27 #include <charconv.h>
       
    28 #endif
       
    29 
       
    30 
       
    31 class Versit
       
    32 /** Provides Versit-specific encoding and character set identifiers. 
       
    33 @publishedAll
       
    34 @released
       
    35 */
       
    36 	{
       
    37 public:
       
    38 	/** Versit-specific encoding identifiers. 
       
    39 	@publishedAll
       
    40 	@released
       
    41 	*/
       
    42 	enum TVersitEncoding
       
    43 		{
       
    44 		/** No encoding. */
       
    45 		ENoEncoding,
       
    46 		/** Quoted Printable encoding. */
       
    47 		EQuotedPrintableEncoding,
       
    48 		/** Base 64 encoding. */
       
    49 		EBase64Encoding,
       
    50 
       
    51 		// Used internally - not to be used by versit clients
       
    52 		/** Eight bit encoding. */
       
    53 		EEightBitEncoding
       
    54 		};
       
    55 
       
    56 	/** Versit-specific character set identifiers. These are used in the Versit API 
       
    57 	to represent foreign (non-Unicode) character sets for vCard and vCalendar 
       
    58 	properties. 
       
    59 	@publishedAll
       
    60 	@released */
       
    61 	enum TVersitCharSet
       
    62 		{
       
    63 		/** Unknown character set. */
       
    64 		EUnknownCharSet,
       
    65 		/** ASCII (7-bit).*/
       
    66 		EUSAsciiCharSet,	
       
    67 		/** UTF-8 Unicode transformation format. */
       
    68 		EUTF8CharSet,
       
    69 		/** UTF-7 Unicode transformation format. */
       
    70 		EUTF7CharSet,
       
    71 		/** ISO 8859-1 (8-bit). */
       
    72 		EISO88591CharSet,
       
    73 		/** ISO 8859-2 (8-bit). */
       
    74 		EISO88592CharSet,
       
    75 		/** ISO 8859-4 (8-bit). */
       
    76 		EISO88594CharSet,
       
    77 		/** ISO 8859-5 (8-bit). */
       
    78 		EISO88595CharSet,
       
    79 		/** ISO 8859-7 (8-bit). */
       
    80 		EISO88597CharSet,
       
    81 		/** ISO 8859-9 (8-bit). */
       
    82 		EISO88599CharSet,
       
    83 		/** ISO 8859-3 (8-bit). */
       
    84 		EISO88593CharSet,
       
    85 		/** ISO 8859-10 (8-bit). */
       
    86 		EISO885910CharSet,
       
    87 		/** GB 2312. */
       
    88 		EGB231280CharSet,
       
    89 		/** GBK. */
       
    90 		EGBKCharSet,
       
    91 		/** Big 5. */
       
    92 		EBIG5CharSet,
       
    93 		/** ISO-2022-JP. */
       
    94 		EISO2022JPCharSet,
       
    95 		/** EUC-JP. */
       
    96 		EEUCJPCharSet,
       
    97 		/** Shift JIS. */
       
    98 		EShiftJISCharSet,
       
    99 		/** JIS. */
       
   100 		EJISCharSet,
       
   101 		/** Must be first character set. */
       
   102 		EFirstCharSet=EUSAsciiCharSet,
       
   103 		/** Must be last character set. */
       
   104 		ELastCharSet=EJISCharSet
       
   105 		};
       
   106 
       
   107 	class TEncodingAndCharset
       
   108 	/** Specifies an encoding, a character set and a character set converter. 
       
   109 	@publishedAll
       
   110 	@released */
       
   111 		{
       
   112 	public:
       
   113 		inline TEncodingAndCharset(TVersitEncoding aEncoding,TUint aCharSetId) :iEncoding(aEncoding), iCharSetId(aCharSetId) 
       
   114 		/** The C++ constructor initialises the encoding and character set.
       
   115 	
       
   116 		@param aEncoding An encoding.
       
   117 		@param aCharSetId A character set. */
       
   118 			{}
       
   119 	public:
       
   120 		/** An encoding. */
       
   121 		TVersitEncoding iEncoding;
       
   122 		/** A character set. */
       
   123 		TUint iCharSetId;
       
   124 		/** A character set converter. */
       
   125 		CCnvCharacterSetConverter* iConverter;
       
   126 		};
       
   127 	};
       
   128 
       
   129 class CVersitUnicodeUtils : public CBase
       
   130 /** Versit Unicode utilities class. 
       
   131 
       
   132 This enables conversion between Unicode and ISO character sets. 
       
   133 @publishedAll
       
   134 @released
       
   135 */
       
   136 	{
       
   137 public:
       
   138 	IMPORT_C ~CVersitUnicodeUtils();
       
   139 	IMPORT_C HBufC8* NarrowL(const TDesC& aDesC);
       
   140 	IMPORT_C HBufC8* NarrowLC(const TDesC& aDesC);
       
   141 	IMPORT_C HBufC* WidenL(const TDesC8& aDesC8);
       
   142 	IMPORT_C HBufC* WidenLC(const TDesC8& aDesC8);
       
   143 	IMPORT_C void CreateConverterL();
       
   144 	CCnvCharacterSetConverter::TAvailability SetCurrentCharSetL(TUint aCharacterSet);
       
   145 
       
   146 public:
       
   147 	inline CCnvCharacterSetConverter& CharacterSetConverter() const;
       
   148 	inline TUint ConvertStandardNameL(const TDesC8& aStandardNameOfCharacterSet);
       
   149 	inline HBufC8* StandardNameL(TUint aCharSetId);
       
   150 	TUint AutoDetectCharSetL(const TDesC8& aSample,const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* aAutoDetectCharSets);
       
   151 
       
   152 private:
       
   153 	RFs iFsSession;
       
   154 	CCnvCharacterSetConverter* iUnicodeConverter;
       
   155 	TBool iFsConnected;
       
   156 	TUint iCurrentConverterCharSet;
       
   157 	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* iCharSetsAvailable;
       
   158 	};
       
   159 
       
   160 
       
   161 inline CCnvCharacterSetConverter& CVersitUnicodeUtils::CharacterSetConverter() const
       
   162 /** Returns the character set converter created in CreateConverterL().
       
   163 	
       
   164 @return A character set converter. */
       
   165 	{
       
   166 	return *iUnicodeConverter;
       
   167 	}
       
   168 inline TUint CVersitUnicodeUtils::ConvertStandardNameL(const TDesC8& aStandardNameOfCharacterSet)
       
   169 /** Returns the Symbian OS UID for a character set from its Internet-standard 
       
   170 name.
       
   171 	
       
   172 @param aStandardNameOfCharacterSet Internet-standard name of a character set 
       
   173 encoded in 8-bit ASCII.
       
   174 @return The Symbian OS UID of the specified character set. If the name is not 
       
   175 known, zero is returned. */
       
   176 	{
       
   177 	return iUnicodeConverter->ConvertStandardNameOfCharacterSetToIdentifierL(aStandardNameOfCharacterSet,iFsSession);
       
   178 	}
       
   179 inline HBufC8* CVersitUnicodeUtils::StandardNameL(TUint aCharSetId)
       
   180 /** Returns the Internet-standard name of a character set, from its Symbian OS UID. 
       
   181 
       
   182 @param aCharSetId The Symbian OS UID of a character set.
       
   183 @return The Internet-standard name or MIME name of the specified character 
       
   184 set, or NULL if the UID is not known. The name is encoded in 8-bit ASCII. */
       
   185 	{
       
   186 	return iUnicodeConverter->ConvertCharacterSetIdentifierToStandardNameL(aCharSetId,iFsSession);
       
   187 	}
       
   188 
       
   189 #endif