epoc32/include/textresolver.h
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
equal deleted inserted replaced
3:e1b950c65cb4 4:837f303aceeb
     1 /*
     1 /*
     2 * Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8 *
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Offers functionality for resolving corresponding error texts
    14 * Description:
    15 *                for error codes. 
       
    16 *
    15 *
    17 */
    16 */
    18 
    17 
    19 
    18 
    20 
    19 
    21 #if !defined TEXT_RESOLVER_H
    20 
       
    21 #ifndef TEXT_RESOLVER_H
    22 #define TEXT_RESOLVER_H
    22 #define TEXT_RESOLVER_H
    23 
    23 
    24 #include <coemain.h>    //  CCoeEnv
    24 #include <coemain.h>    //  CCoeEnv
    25 #include <TextResolver.hrh> // Resource flags 
    25 #include <textresolver.hrh> // Resource flags 
       
    26 #include <eikenv.h>    //  CEikonEnv
    26 
    27 
    27 // DEFINES
    28 // DEFINES
    28 typedef CArrayFixFlat<TInt> CErrorResourceIdArray;
    29 typedef CArrayFixFlat<TInt> CErrorResourceIdArray;
    29 typedef CArrayFixFlat<TInt> CErrorResourceFlagArray;
    30 typedef CArrayFixFlat<TInt> CErrorResourceFlagArray;
    30 
    31 
   126 * @endcode
   127 * @endcode
   127 *
   128 *
   128 * @lib commonengine.lib
   129 * @lib commonengine.lib
   129 * @since S60 2.0
   130 * @since S60 2.0
   130 */
   131 */
   131 
       
   132 class CTextResolver : public CBase
   132 class CTextResolver : public CBase
   133     {
   133     {
       
   134 public:
       
   135     /**
       
   136     * Defines used error contexts. 
       
   137     * Optional error contexes for aiding the mapping of error codes to 
       
   138     * texts in a unique way. If no context is given the assumption is 
       
   139     * that error codes are unique.
       
   140     */
       
   141     enum TErrorContext
       
   142         {
       
   143         /** Context is defined automatically from error code value.
       
   144         * Here it is assumed that each error code is unique and in
       
   145         * own range. This is a default value when resolving errors. */
       
   146         ECtxAutomatic = 0,
       
   147         /** Context text is not added to the beginning of the resolved error text,
       
   148         * just context separator ':' and newline are added. */
       
   149         ECtxNoCtx = 1,
       
   150         /** No context text, context separator ':' or newline added to the 
       
   151         * beginning of the resolved error text. */
       
   152         ECtxNoCtxNoSeparator = 2
       
   153         };
       
   154 public:
       
   155     IMPORT_C static CTextResolver* NewL(CCoeEnv& aEnv);
       
   156     IMPORT_C static CTextResolver* NewLC(CCoeEnv& aEnv);
       
   157     IMPORT_C static CTextResolver* NewL();
       
   158 	IMPORT_C static CTextResolver* NewLC();
       
   159     IMPORT_C ~CTextResolver();
       
   160 	IMPORT_C const TDesC& ResolveErrorString(TInt aError, TInt& aTextId, TUint& aFlags,TErrorContext aContext = ECtxAutomatic);
       
   161     IMPORT_C const TDesC& ResolveErrorString(TInt aError, TErrorContext aContext = ECtxAutomatic);
       
   162 private: // Construction
       
   163     virtual TInt ResourceForError(TInt aError);
       
   164     virtual void LoadResourceFilesL() { ASSERT(0); }	// deprecated
       
   165     CTextResolver(CCoeEnv& aEnv);
       
   166     CTextResolver();
       
   167     void ConstructL();
       
   168     
       
   169     // Utility
       
   170     void DoRawReadOfSystemErrorResourcesToArraysL(TInt& aError, TInt& aTextId);
       
   171     void Reset();
       
   172     void ReadLocalizedSeparatorCharacterFromResourceL(CCoeEnv& aCoeEnv);
       
   173     void ReadLocalizedSeparatorCharacterFromResourceAndPrepareResourceReaderLC(TResourceReader& aResReader);
   134 
   174 
   135     public:
   175     // returns NULL if fails
   136 
   176     static HBufC* AllocReadUnicodeString(RResourceFile& aResFile, TInt aTextId);
   137         /**
   177     /** Returns false if any memory allocation fails or initial values 
   138         * Defines used error contexts. 
   178 	of necessary pointers are NULL, indicating alloc failure earlier.*/
   139         * Optional error contexes for aiding the mapping of error codes to 
   179     TBool AddContextAndSeparator(TErrorContext aContext);
   140         * texts in a unique way. If no context is given the assumption is 
   180     void AllocBuffersL();
   141         * that error codes are unique.
   181     void DoResolveErrorStringL(TInt aError, TInt& aTextId, TUint& aFlags);
   142         */
   182 private:
   143         enum TErrorContext
   183     CCoeEnv* iCoe;
   144             {
   184     RResourceFile iResFile;
   145             /** Context is defined automatically from error code value.
   185     TInt iRDSupport;
   146             * Here it is assumed that each error code is unique and in
   186     TInt iBaseResourceFileOffset;
   147             * own range. This is a default value when resolving errors.
   187     CArrayFix<TInt>* iStartError;
   148             */
   188     CArrayFix<TInt>* iAppTexts;
   149             ECtxAutomatic = 0,
   189     CArrayPtr<CErrorResourceIdArray>*   iErrorTexts;	// Array of arrays of ints
   150             /** Context text is not added to the beginning of the resolved error text,
   190     CArrayPtr<CErrorResourceFlagArray>* iFlags;			// Array of arrays of ints
   151             * just context separator ':' and newline are added.
   191     HBufC* iTextBuffer;
   152             */
   192     HBufC* iTitleText;
   153             ECtxNoCtx = 1,
   193     HBufC* iContextSeparator;
   154             /** No context text, context separator ':' or newline added to the 
   194     RFs iFs;
   155             * beginning of the resolved error text.
   195     TPtrC  iTruncatedTextPointer;
   156             */
   196 	};
   157             ECtxNoCtxNoSeparator = 2
       
   158             };
       
   159     public:
       
   160         /**
       
   161          * Two-phase constructor method that is used to create a new instance
       
   162          * of the CTextResolver class. The implementation uses the passed 
       
   163          * CCoeEnv instance to access the resource files.
       
   164          *
       
   165          * @param aEnv the CCoeEnv instance to be used to access the resource
       
   166          * files.
       
   167          * @return a pointer to a new instance of the CTextResolver class.
       
   168          */
       
   169         IMPORT_C static CTextResolver* NewL(CCoeEnv& aEnv);
       
   170            
       
   171          /**
       
   172          * Constructor creates a new instance of CTextResolver. The 
       
   173          * implementation uses the passed CCoeEnv instance to access the 
       
   174          * resource files. Leaves the object on the cleanup stack.
       
   175          *
       
   176          * @param aEnv the CCoeEnv instance to be used to access the resource
       
   177          * files.
       
   178          * @return a pointer to a new instance of the CTextResolver class.
       
   179          */
       
   180         IMPORT_C static CTextResolver* NewLC(CCoeEnv& aEnv);
       
   181         
       
   182          /**
       
   183          * Constructor creates a new instance of CTextResolver. Resource files 
       
   184          * are accessed through the RResourceFile API.
       
   185          *
       
   186          * @return a pointer to a new instance of the CTextResolver class.
       
   187          */
       
   188         IMPORT_C static CTextResolver* NewL();
       
   189 
       
   190          /**
       
   191          * Constructor creates a new instance of CTextResolver.Resource files 
       
   192          * are accessed through the RResourceFile API. Leaves the object on 
       
   193          * the cleanup stack.
       
   194          *
       
   195          * @return a pointer to a new instance of the CTextResolver class.
       
   196          */
       
   197         IMPORT_C static CTextResolver* NewLC();
       
   198 
       
   199         
       
   200         /** 
       
   201         * Destructor 
       
   202         */
       
   203         IMPORT_C ~CTextResolver();
       
   204 
       
   205         /**
       
   206         * Resolves the given error code and returns the error text for the
       
   207         * resolved error. Resolved text can be of any length. This version
       
   208         * is for advanced use
       
   209         *
       
   210         * @param aError The error code to be resolved.
       
   211         * @param aTextId ID of the returned text.
       
   212         * @param aFlags The priority of the returned error. The priority is 
       
   213         * defined by the this module! Flags are defined in textresolver.hrh.
       
   214         * @param aContext Optional context for error numbers. If the aContext 
       
   215         * parameter is not passed to the function, it uses the default value
       
   216         * ECtxAutomatic. 
       
   217         * @return the error text for the resolved error. "System error" (in 
       
   218         * English localisation) is returned when error code is not known. For 
       
   219         * unknown errors blank error flag (flags are defined in 
       
   220         * textresolver.hrh) is also set to hide errors without proper 
       
   221         * explanation. There is no limit on how long the resolved string 
       
   222         * can be.
       
   223         */
       
   224 		IMPORT_C const TDesC& ResolveErrorString(
       
   225              TInt aError,
       
   226              TInt& aTextId,
       
   227              TUint& aFlags,
       
   228              TErrorContext aContext = ECtxAutomatic);
       
   229 
       
   230         /**
       
   231         * Resolves the given error code and returns the error text for the
       
   232         * resolved error. Resolved text can be of any length. This version 
       
   233         * is for "normal" use.
       
   234         *
       
   235         * @param aError The error code to be resolved.
       
   236         * @param aContext Optional context for error numbers. If the aContext 
       
   237         * parameter is not passed to the function, it uses the default value
       
   238         * ECtxAutomatic. 
       
   239         * @return the error text for the resolved error. "System error" (in 
       
   240         * English localisation) is returned when error code is not known. For 
       
   241         * unknown errors blank error flag (flags are defined in 
       
   242         * textresolver.hrh) is also set to hide errors without proper 
       
   243         * explanation. There is no limit on how long the resolved string
       
   244         * can be.
       
   245         */
       
   246 	    IMPORT_C const TDesC& ResolveErrorString(
       
   247              TInt aError,
       
   248              TErrorContext aContext = ECtxAutomatic);
       
   249 
       
   250 	private:
       
   251         
       
   252         virtual TInt ResourceForError(TInt aError);
       
   253         virtual void LoadResourceFilesL();
       
   254 
       
   255         // Construction
       
   256         CTextResolver(CCoeEnv& aEnv);
       
   257         CTextResolver();
       
   258         void ConstructL();
       
   259 
       
   260         // Utility
       
   261         void FindFullPathOfResourceFile(TFileName& aResFile) const;
       
   262         void ReadResourcesToArraysL(TInt& aError, TInt& aTextId);
       
   263         void Reset();
       
   264         void PrepareReaderLC(TResourceReader& reader);
       
   265 
       
   266         // returns NULL if fails
       
   267         HBufC* ReadUnicodeString(const TInt& aTextId);
       
   268 
       
   269         // returns false if any memory allocation fails or initial values 
       
   270         // of necessary pointers are NULL, indicating alloc failure earlier.
       
   271         TBool AddContextAndSeparator(TErrorContext aContext);
       
   272 
       
   273     private:
       
   274         
       
   275         CCoeEnv*                            iCoe;
       
   276         RResourceFile                       iRFile;
       
   277         TInt                                iRDSupport;
       
   278         TInt                                iBaseResourceFileOffset;
       
   279         CArrayFix<TInt>*                    iStartError;
       
   280         CArrayFix<TInt>*                    iAppTexts;
       
   281         CArrayPtr<CErrorResourceIdArray>*   iErrorTexts;
       
   282         CArrayPtr<CErrorResourceFlagArray>* iFlags;
       
   283         HBufC*                              iTextBuffer;
       
   284         HBufC*                              iAppNameText;
       
   285         HBufC*                              iContextSeparator;
       
   286         RFs                                 iFs;
       
   287         TPtrC                               iTruncatedTextPointer;
       
   288     };
       
   289 
   197 
   290 #endif
   198 #endif
   291 
   199 
   292 // End of File