epoc32/include/textresolver.h
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
     1.1 --- a/epoc32/include/textresolver.h	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ b/epoc32/include/textresolver.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -1,28 +1,29 @@
     1.4  /*
     1.5 -* Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.7  * All rights reserved.
     1.8  * This component and the accompanying materials are made available
     1.9 -* 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
    1.10 +* under the terms of "Eclipse Public License v1.0"
    1.11  * which accompanies this distribution, and is available
    1.12 -* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.13 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.14  *
    1.15  * Initial Contributors:
    1.16  * Nokia Corporation - initial contribution.
    1.17  *
    1.18  * Contributors:
    1.19  *
    1.20 -* Description:  Offers functionality for resolving corresponding error texts
    1.21 -*                for error codes. 
    1.22 +* Description:
    1.23  *
    1.24  */
    1.25  
    1.26  
    1.27  
    1.28 -#if !defined TEXT_RESOLVER_H
    1.29 +
    1.30 +#ifndef TEXT_RESOLVER_H
    1.31  #define TEXT_RESOLVER_H
    1.32  
    1.33  #include <coemain.h>    //  CCoeEnv
    1.34 -#include <TextResolver.hrh> // Resource flags 
    1.35 +#include <textresolver.hrh> // Resource flags 
    1.36 +#include <eikenv.h>    //  CEikonEnv
    1.37  
    1.38  // DEFINES
    1.39  typedef CArrayFixFlat<TInt> CErrorResourceIdArray;
    1.40 @@ -128,165 +129,71 @@
    1.41  * @lib commonengine.lib
    1.42  * @since S60 2.0
    1.43  */
    1.44 -
    1.45  class CTextResolver : public CBase
    1.46      {
    1.47 +public:
    1.48 +    /**
    1.49 +    * Defines used error contexts. 
    1.50 +    * Optional error contexes for aiding the mapping of error codes to 
    1.51 +    * texts in a unique way. If no context is given the assumption is 
    1.52 +    * that error codes are unique.
    1.53 +    */
    1.54 +    enum TErrorContext
    1.55 +        {
    1.56 +        /** Context is defined automatically from error code value.
    1.57 +        * Here it is assumed that each error code is unique and in
    1.58 +        * own range. This is a default value when resolving errors. */
    1.59 +        ECtxAutomatic = 0,
    1.60 +        /** Context text is not added to the beginning of the resolved error text,
    1.61 +        * just context separator ':' and newline are added. */
    1.62 +        ECtxNoCtx = 1,
    1.63 +        /** No context text, context separator ':' or newline added to the 
    1.64 +        * beginning of the resolved error text. */
    1.65 +        ECtxNoCtxNoSeparator = 2
    1.66 +        };
    1.67 +public:
    1.68 +    IMPORT_C static CTextResolver* NewL(CCoeEnv& aEnv);
    1.69 +    IMPORT_C static CTextResolver* NewLC(CCoeEnv& aEnv);
    1.70 +    IMPORT_C static CTextResolver* NewL();
    1.71 +	IMPORT_C static CTextResolver* NewLC();
    1.72 +    IMPORT_C ~CTextResolver();
    1.73 +	IMPORT_C const TDesC& ResolveErrorString(TInt aError, TInt& aTextId, TUint& aFlags,TErrorContext aContext = ECtxAutomatic);
    1.74 +    IMPORT_C const TDesC& ResolveErrorString(TInt aError, TErrorContext aContext = ECtxAutomatic);
    1.75 +private: // Construction
    1.76 +    virtual TInt ResourceForError(TInt aError);
    1.77 +    virtual void LoadResourceFilesL() { ASSERT(0); }	// deprecated
    1.78 +    CTextResolver(CCoeEnv& aEnv);
    1.79 +    CTextResolver();
    1.80 +    void ConstructL();
    1.81 +    
    1.82 +    // Utility
    1.83 +    void DoRawReadOfSystemErrorResourcesToArraysL(TInt& aError, TInt& aTextId);
    1.84 +    void Reset();
    1.85 +    void ReadLocalizedSeparatorCharacterFromResourceL(CCoeEnv& aCoeEnv);
    1.86 +    void ReadLocalizedSeparatorCharacterFromResourceAndPrepareResourceReaderLC(TResourceReader& aResReader);
    1.87  
    1.88 -    public:
    1.89 -
    1.90 -        /**
    1.91 -        * Defines used error contexts. 
    1.92 -        * Optional error contexes for aiding the mapping of error codes to 
    1.93 -        * texts in a unique way. If no context is given the assumption is 
    1.94 -        * that error codes are unique.
    1.95 -        */
    1.96 -        enum TErrorContext
    1.97 -            {
    1.98 -            /** Context is defined automatically from error code value.
    1.99 -            * Here it is assumed that each error code is unique and in
   1.100 -            * own range. This is a default value when resolving errors.
   1.101 -            */
   1.102 -            ECtxAutomatic = 0,
   1.103 -            /** Context text is not added to the beginning of the resolved error text,
   1.104 -            * just context separator ':' and newline are added.
   1.105 -            */
   1.106 -            ECtxNoCtx = 1,
   1.107 -            /** No context text, context separator ':' or newline added to the 
   1.108 -            * beginning of the resolved error text.
   1.109 -            */
   1.110 -            ECtxNoCtxNoSeparator = 2
   1.111 -            };
   1.112 -    public:
   1.113 -        /**
   1.114 -         * Two-phase constructor method that is used to create a new instance
   1.115 -         * of the CTextResolver class. The implementation uses the passed 
   1.116 -         * CCoeEnv instance to access the resource files.
   1.117 -         *
   1.118 -         * @param aEnv the CCoeEnv instance to be used to access the resource
   1.119 -         * files.
   1.120 -         * @return a pointer to a new instance of the CTextResolver class.
   1.121 -         */
   1.122 -        IMPORT_C static CTextResolver* NewL(CCoeEnv& aEnv);
   1.123 -           
   1.124 -         /**
   1.125 -         * Constructor creates a new instance of CTextResolver. The 
   1.126 -         * implementation uses the passed CCoeEnv instance to access the 
   1.127 -         * resource files. Leaves the object on the cleanup stack.
   1.128 -         *
   1.129 -         * @param aEnv the CCoeEnv instance to be used to access the resource
   1.130 -         * files.
   1.131 -         * @return a pointer to a new instance of the CTextResolver class.
   1.132 -         */
   1.133 -        IMPORT_C static CTextResolver* NewLC(CCoeEnv& aEnv);
   1.134 -        
   1.135 -         /**
   1.136 -         * Constructor creates a new instance of CTextResolver. Resource files 
   1.137 -         * are accessed through the RResourceFile API.
   1.138 -         *
   1.139 -         * @return a pointer to a new instance of the CTextResolver class.
   1.140 -         */
   1.141 -        IMPORT_C static CTextResolver* NewL();
   1.142 -
   1.143 -         /**
   1.144 -         * Constructor creates a new instance of CTextResolver.Resource files 
   1.145 -         * are accessed through the RResourceFile API. Leaves the object on 
   1.146 -         * the cleanup stack.
   1.147 -         *
   1.148 -         * @return a pointer to a new instance of the CTextResolver class.
   1.149 -         */
   1.150 -        IMPORT_C static CTextResolver* NewLC();
   1.151 -
   1.152 -        
   1.153 -        /** 
   1.154 -        * Destructor 
   1.155 -        */
   1.156 -        IMPORT_C ~CTextResolver();
   1.157 -
   1.158 -        /**
   1.159 -        * Resolves the given error code and returns the error text for the
   1.160 -        * resolved error. Resolved text can be of any length. This version
   1.161 -        * is for advanced use
   1.162 -        *
   1.163 -        * @param aError The error code to be resolved.
   1.164 -        * @param aTextId ID of the returned text.
   1.165 -        * @param aFlags The priority of the returned error. The priority is 
   1.166 -        * defined by the this module! Flags are defined in textresolver.hrh.
   1.167 -        * @param aContext Optional context for error numbers. If the aContext 
   1.168 -        * parameter is not passed to the function, it uses the default value
   1.169 -        * ECtxAutomatic. 
   1.170 -        * @return the error text for the resolved error. "System error" (in 
   1.171 -        * English localisation) is returned when error code is not known. For 
   1.172 -        * unknown errors blank error flag (flags are defined in 
   1.173 -        * textresolver.hrh) is also set to hide errors without proper 
   1.174 -        * explanation. There is no limit on how long the resolved string 
   1.175 -        * can be.
   1.176 -        */
   1.177 -		IMPORT_C const TDesC& ResolveErrorString(
   1.178 -             TInt aError,
   1.179 -             TInt& aTextId,
   1.180 -             TUint& aFlags,
   1.181 -             TErrorContext aContext = ECtxAutomatic);
   1.182 -
   1.183 -        /**
   1.184 -        * Resolves the given error code and returns the error text for the
   1.185 -        * resolved error. Resolved text can be of any length. This version 
   1.186 -        * is for "normal" use.
   1.187 -        *
   1.188 -        * @param aError The error code to be resolved.
   1.189 -        * @param aContext Optional context for error numbers. If the aContext 
   1.190 -        * parameter is not passed to the function, it uses the default value
   1.191 -        * ECtxAutomatic. 
   1.192 -        * @return the error text for the resolved error. "System error" (in 
   1.193 -        * English localisation) is returned when error code is not known. For 
   1.194 -        * unknown errors blank error flag (flags are defined in 
   1.195 -        * textresolver.hrh) is also set to hide errors without proper 
   1.196 -        * explanation. There is no limit on how long the resolved string
   1.197 -        * can be.
   1.198 -        */
   1.199 -	    IMPORT_C const TDesC& ResolveErrorString(
   1.200 -             TInt aError,
   1.201 -             TErrorContext aContext = ECtxAutomatic);
   1.202 -
   1.203 -	private:
   1.204 -        
   1.205 -        virtual TInt ResourceForError(TInt aError);
   1.206 -        virtual void LoadResourceFilesL();
   1.207 -
   1.208 -        // Construction
   1.209 -        CTextResolver(CCoeEnv& aEnv);
   1.210 -        CTextResolver();
   1.211 -        void ConstructL();
   1.212 -
   1.213 -        // Utility
   1.214 -        void FindFullPathOfResourceFile(TFileName& aResFile) const;
   1.215 -        void ReadResourcesToArraysL(TInt& aError, TInt& aTextId);
   1.216 -        void Reset();
   1.217 -        void PrepareReaderLC(TResourceReader& reader);
   1.218 -
   1.219 -        // returns NULL if fails
   1.220 -        HBufC* ReadUnicodeString(const TInt& aTextId);
   1.221 -
   1.222 -        // returns false if any memory allocation fails or initial values 
   1.223 -        // of necessary pointers are NULL, indicating alloc failure earlier.
   1.224 -        TBool AddContextAndSeparator(TErrorContext aContext);
   1.225 -
   1.226 -    private:
   1.227 -        
   1.228 -        CCoeEnv*                            iCoe;
   1.229 -        RResourceFile                       iRFile;
   1.230 -        TInt                                iRDSupport;
   1.231 -        TInt                                iBaseResourceFileOffset;
   1.232 -        CArrayFix<TInt>*                    iStartError;
   1.233 -        CArrayFix<TInt>*                    iAppTexts;
   1.234 -        CArrayPtr<CErrorResourceIdArray>*   iErrorTexts;
   1.235 -        CArrayPtr<CErrorResourceFlagArray>* iFlags;
   1.236 -        HBufC*                              iTextBuffer;
   1.237 -        HBufC*                              iAppNameText;
   1.238 -        HBufC*                              iContextSeparator;
   1.239 -        RFs                                 iFs;
   1.240 -        TPtrC                               iTruncatedTextPointer;
   1.241 -    };
   1.242 +    // returns NULL if fails
   1.243 +    static HBufC* AllocReadUnicodeString(RResourceFile& aResFile, TInt aTextId);
   1.244 +    /** Returns false if any memory allocation fails or initial values 
   1.245 +	of necessary pointers are NULL, indicating alloc failure earlier.*/
   1.246 +    TBool AddContextAndSeparator(TErrorContext aContext);
   1.247 +    void AllocBuffersL();
   1.248 +    void DoResolveErrorStringL(TInt aError, TInt& aTextId, TUint& aFlags);
   1.249 +private:
   1.250 +    CCoeEnv* iCoe;
   1.251 +    RResourceFile iResFile;
   1.252 +    TInt iRDSupport;
   1.253 +    TInt iBaseResourceFileOffset;
   1.254 +    CArrayFix<TInt>* iStartError;
   1.255 +    CArrayFix<TInt>* iAppTexts;
   1.256 +    CArrayPtr<CErrorResourceIdArray>*   iErrorTexts;	// Array of arrays of ints
   1.257 +    CArrayPtr<CErrorResourceFlagArray>* iFlags;			// Array of arrays of ints
   1.258 +    HBufC* iTextBuffer;
   1.259 +    HBufC* iTitleText;
   1.260 +    HBufC* iContextSeparator;
   1.261 +    RFs iFs;
   1.262 +    TPtrC  iTruncatedTextPointer;
   1.263 +	};
   1.264  
   1.265  #endif
   1.266  
   1.267 -// End of File