williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
3 |
* All rights reserved.
|
williamr@2
|
4 |
* This component and the accompanying materials are made available
|
williamr@2
|
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
|
williamr@2
|
6 |
* which accompanies this distribution, and is available
|
williamr@2
|
7 |
* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Initial Contributors:
|
williamr@2
|
10 |
* Nokia Corporation - initial contribution.
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Contributors:
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
* Description: Offers functionality for resolving corresponding error texts
|
williamr@2
|
15 |
* for error codes.
|
williamr@2
|
16 |
*
|
williamr@2
|
17 |
*/
|
williamr@2
|
18 |
|
williamr@2
|
19 |
|
williamr@2
|
20 |
|
williamr@2
|
21 |
#if !defined TEXT_RESOLVER_H
|
williamr@2
|
22 |
#define TEXT_RESOLVER_H
|
williamr@2
|
23 |
|
williamr@2
|
24 |
#include <coemain.h> // CCoeEnv
|
williamr@2
|
25 |
#include <TextResolver.hrh> // Resource flags
|
williamr@2
|
26 |
|
williamr@2
|
27 |
// DEFINES
|
williamr@2
|
28 |
typedef CArrayFixFlat<TInt> CErrorResourceIdArray;
|
williamr@2
|
29 |
typedef CArrayFixFlat<TInt> CErrorResourceFlagArray;
|
williamr@2
|
30 |
|
williamr@2
|
31 |
/**
|
williamr@2
|
32 |
* Class offers functionality for resolving corresponding error texts for
|
williamr@2
|
33 |
* error codes. Text Resolver API provides operations with which a specific
|
williamr@2
|
34 |
* error code can be resolved to a human readable text. Descriptions for the
|
williamr@2
|
35 |
* different error codes must be defined in the resource files of this
|
williamr@2
|
36 |
* component.
|
williamr@2
|
37 |
*
|
williamr@2
|
38 |
* Text Resolver uses the CCoeEnv environment class to access the resource
|
williamr@2
|
39 |
* files if the CCoeEnv environment is available. If the CCoeEnv environment
|
williamr@2
|
40 |
* is not available, the files are accessed through the RResourceFile API.
|
williamr@2
|
41 |
*
|
williamr@2
|
42 |
* The API consist of the CTextResolver class which is used together with
|
williamr@2
|
43 |
* Text Resolver flags defined in textresolver.hrh file. The flags are used
|
williamr@2
|
44 |
* to tell the priority of the error to the client:
|
williamr@2
|
45 |
*
|
williamr@2
|
46 |
* - EErrorResBlankErrorFlag is used to tell that error has no proper explanation.
|
williamr@2
|
47 |
* - EErrorResUnknownErrorFlag indicates that Text Resolver does not support the error.
|
williamr@2
|
48 |
* - EErrorResOOMFlag Flag is returned while processing KErrNoMemory error code.
|
williamr@2
|
49 |
*
|
williamr@2
|
50 |
*
|
williamr@2
|
51 |
* Usage:
|
williamr@2
|
52 |
*
|
williamr@2
|
53 |
* @code
|
williamr@2
|
54 |
* #include <textresolver.h>
|
williamr@2
|
55 |
*
|
williamr@2
|
56 |
* // Typically used as an instance variable.
|
williamr@2
|
57 |
*
|
williamr@2
|
58 |
* // Call the factory method NewLC() to create a new instance of CTextResolver.
|
williamr@2
|
59 |
* // NewLC() method leaves the instance of the object on the cleanup stack.
|
williamr@2
|
60 |
* // The passed CCoeEnv instance is needed to access the resource files.
|
williamr@2
|
61 |
* CTextResolver* iTextResolver = CTextResolver::NewLC(*iCoeEnv);
|
williamr@2
|
62 |
*
|
williamr@2
|
63 |
* // // Error Resolving, simple:
|
williamr@2
|
64 |
*
|
williamr@2
|
65 |
* // Get error code to be resolved.
|
williamr@2
|
66 |
* // TInt err1 = MyMethod(KInvalidValue);
|
williamr@2
|
67 |
* TInt err1 = KErrNoMemory;
|
williamr@2
|
68 |
*
|
williamr@2
|
69 |
* TPtrC buf1; // For returned error text
|
williamr@2
|
70 |
*
|
williamr@2
|
71 |
* if (err1 != KErrNone)
|
williamr@2
|
72 |
* {
|
williamr@2
|
73 |
* // Resolve the given error code.
|
williamr@2
|
74 |
* // The operation returns the error text for the resolved error.
|
williamr@2
|
75 |
* // There's no limit how long the resolved string can be.
|
williamr@2
|
76 |
* // Add context to 2nd param if needed.
|
williamr@2
|
77 |
* buf1.Set(iTextResolver->ResolveErrorString(err));
|
williamr@2
|
78 |
* }
|
williamr@2
|
79 |
* else
|
williamr@2
|
80 |
* {
|
williamr@2
|
81 |
* // Do something.
|
williamr@2
|
82 |
* }
|
williamr@2
|
83 |
*
|
williamr@2
|
84 |
* // Note that buf1 will only be valid as long as CTextResolver
|
williamr@2
|
85 |
* // instance is alive and no new error is resolved by the same instance.
|
williamr@2
|
86 |
* // If for some reason you need to store the resolved error
|
williamr@2
|
87 |
* // beyond immediate use, make a copy of it.
|
williamr@2
|
88 |
*
|
williamr@2
|
89 |
* // Error Resolving, advanced:
|
williamr@2
|
90 |
*
|
williamr@2
|
91 |
* // Get error code to be resolved.
|
williamr@2
|
92 |
* // TInt err2 = MyMethod(KInvalidValue);
|
williamr@2
|
93 |
* TInt err2 = KErrNotSupported;
|
williamr@2
|
94 |
*
|
williamr@2
|
95 |
* TInt textId(0); // ID of the returned text
|
williamr@2
|
96 |
* TUint flags(0); // Priority of the returned error
|
williamr@2
|
97 |
* TPtrC buf2; // For returned error text
|
williamr@2
|
98 |
*
|
williamr@2
|
99 |
* if (err2 != KErrNone)
|
williamr@2
|
100 |
* {
|
williamr@2
|
101 |
* // Resolve the given error code.
|
williamr@2
|
102 |
* // The operation returns the error text for the resolved error.
|
williamr@2
|
103 |
* // There's no limit on how long the resolved string can be.
|
williamr@2
|
104 |
* // Add Context to 4th param if needed.
|
williamr@2
|
105 |
* buf2.Set(iTextResolver->ResolveErrorString(err, textId, flags));
|
williamr@2
|
106 |
*
|
williamr@2
|
107 |
* if (flags & EErrorResUnknownErrorFlag)
|
williamr@2
|
108 |
* {
|
williamr@2
|
109 |
* // The flag indicates that Text Resolver does not support
|
williamr@2
|
110 |
* // the error code.
|
williamr@2
|
111 |
* // Do something.
|
williamr@2
|
112 |
* }
|
williamr@2
|
113 |
* }
|
williamr@2
|
114 |
* else
|
williamr@2
|
115 |
* {
|
williamr@2
|
116 |
* // Do something.
|
williamr@2
|
117 |
* }
|
williamr@2
|
118 |
*
|
williamr@2
|
119 |
* // Note that buf2 will only be valid as long as CTextResolver
|
williamr@2
|
120 |
* // instance is alive and no new error is resolved by the same instance.
|
williamr@2
|
121 |
* // If for some reason you need to store the resolved error
|
williamr@2
|
122 |
* // beyond immediate use, make a copy of it.
|
williamr@2
|
123 |
*
|
williamr@2
|
124 |
* // iTextResolver, Free loaded resources
|
williamr@2
|
125 |
* CleanupStack::PopAndDestroy();
|
williamr@2
|
126 |
* @endcode
|
williamr@2
|
127 |
*
|
williamr@2
|
128 |
* @lib commonengine.lib
|
williamr@2
|
129 |
* @since S60 2.0
|
williamr@2
|
130 |
*/
|
williamr@2
|
131 |
|
williamr@2
|
132 |
class CTextResolver : public CBase
|
williamr@2
|
133 |
{
|
williamr@2
|
134 |
|
williamr@2
|
135 |
public:
|
williamr@2
|
136 |
|
williamr@2
|
137 |
/**
|
williamr@2
|
138 |
* Defines used error contexts.
|
williamr@2
|
139 |
* Optional error contexes for aiding the mapping of error codes to
|
williamr@2
|
140 |
* texts in a unique way. If no context is given the assumption is
|
williamr@2
|
141 |
* that error codes are unique.
|
williamr@2
|
142 |
*/
|
williamr@2
|
143 |
enum TErrorContext
|
williamr@2
|
144 |
{
|
williamr@2
|
145 |
/** Context is defined automatically from error code value.
|
williamr@2
|
146 |
* Here it is assumed that each error code is unique and in
|
williamr@2
|
147 |
* own range. This is a default value when resolving errors.
|
williamr@2
|
148 |
*/
|
williamr@2
|
149 |
ECtxAutomatic = 0,
|
williamr@2
|
150 |
/** Context text is not added to the beginning of the resolved error text,
|
williamr@2
|
151 |
* just context separator ':' and newline are added.
|
williamr@2
|
152 |
*/
|
williamr@2
|
153 |
ECtxNoCtx = 1,
|
williamr@2
|
154 |
/** No context text, context separator ':' or newline added to the
|
williamr@2
|
155 |
* beginning of the resolved error text.
|
williamr@2
|
156 |
*/
|
williamr@2
|
157 |
ECtxNoCtxNoSeparator = 2
|
williamr@2
|
158 |
};
|
williamr@2
|
159 |
public:
|
williamr@2
|
160 |
/**
|
williamr@2
|
161 |
* Two-phase constructor method that is used to create a new instance
|
williamr@2
|
162 |
* of the CTextResolver class. The implementation uses the passed
|
williamr@2
|
163 |
* CCoeEnv instance to access the resource files.
|
williamr@2
|
164 |
*
|
williamr@2
|
165 |
* @param aEnv the CCoeEnv instance to be used to access the resource
|
williamr@2
|
166 |
* files.
|
williamr@2
|
167 |
* @return a pointer to a new instance of the CTextResolver class.
|
williamr@2
|
168 |
*/
|
williamr@2
|
169 |
IMPORT_C static CTextResolver* NewL(CCoeEnv& aEnv);
|
williamr@2
|
170 |
|
williamr@2
|
171 |
/**
|
williamr@2
|
172 |
* Constructor creates a new instance of CTextResolver. The
|
williamr@2
|
173 |
* implementation uses the passed CCoeEnv instance to access the
|
williamr@2
|
174 |
* resource files. Leaves the object on the cleanup stack.
|
williamr@2
|
175 |
*
|
williamr@2
|
176 |
* @param aEnv the CCoeEnv instance to be used to access the resource
|
williamr@2
|
177 |
* files.
|
williamr@2
|
178 |
* @return a pointer to a new instance of the CTextResolver class.
|
williamr@2
|
179 |
*/
|
williamr@2
|
180 |
IMPORT_C static CTextResolver* NewLC(CCoeEnv& aEnv);
|
williamr@2
|
181 |
|
williamr@2
|
182 |
/**
|
williamr@2
|
183 |
* Constructor creates a new instance of CTextResolver. Resource files
|
williamr@2
|
184 |
* are accessed through the RResourceFile API.
|
williamr@2
|
185 |
*
|
williamr@2
|
186 |
* @return a pointer to a new instance of the CTextResolver class.
|
williamr@2
|
187 |
*/
|
williamr@2
|
188 |
IMPORT_C static CTextResolver* NewL();
|
williamr@2
|
189 |
|
williamr@2
|
190 |
/**
|
williamr@2
|
191 |
* Constructor creates a new instance of CTextResolver.Resource files
|
williamr@2
|
192 |
* are accessed through the RResourceFile API. Leaves the object on
|
williamr@2
|
193 |
* the cleanup stack.
|
williamr@2
|
194 |
*
|
williamr@2
|
195 |
* @return a pointer to a new instance of the CTextResolver class.
|
williamr@2
|
196 |
*/
|
williamr@2
|
197 |
IMPORT_C static CTextResolver* NewLC();
|
williamr@2
|
198 |
|
williamr@2
|
199 |
|
williamr@2
|
200 |
/**
|
williamr@2
|
201 |
* Destructor
|
williamr@2
|
202 |
*/
|
williamr@2
|
203 |
IMPORT_C ~CTextResolver();
|
williamr@2
|
204 |
|
williamr@2
|
205 |
/**
|
williamr@2
|
206 |
* Resolves the given error code and returns the error text for the
|
williamr@2
|
207 |
* resolved error. Resolved text can be of any length. This version
|
williamr@2
|
208 |
* is for advanced use
|
williamr@2
|
209 |
*
|
williamr@2
|
210 |
* @param aError The error code to be resolved.
|
williamr@2
|
211 |
* @param aTextId ID of the returned text.
|
williamr@2
|
212 |
* @param aFlags The priority of the returned error. The priority is
|
williamr@2
|
213 |
* defined by the this module! Flags are defined in textresolver.hrh.
|
williamr@2
|
214 |
* @param aContext Optional context for error numbers. If the aContext
|
williamr@2
|
215 |
* parameter is not passed to the function, it uses the default value
|
williamr@2
|
216 |
* ECtxAutomatic.
|
williamr@2
|
217 |
* @return the error text for the resolved error. "System error" (in
|
williamr@2
|
218 |
* English localisation) is returned when error code is not known. For
|
williamr@2
|
219 |
* unknown errors blank error flag (flags are defined in
|
williamr@2
|
220 |
* textresolver.hrh) is also set to hide errors without proper
|
williamr@2
|
221 |
* explanation. There is no limit on how long the resolved string
|
williamr@2
|
222 |
* can be.
|
williamr@2
|
223 |
*/
|
williamr@2
|
224 |
IMPORT_C const TDesC& ResolveErrorString(
|
williamr@2
|
225 |
TInt aError,
|
williamr@2
|
226 |
TInt& aTextId,
|
williamr@2
|
227 |
TUint& aFlags,
|
williamr@2
|
228 |
TErrorContext aContext = ECtxAutomatic);
|
williamr@2
|
229 |
|
williamr@2
|
230 |
/**
|
williamr@2
|
231 |
* Resolves the given error code and returns the error text for the
|
williamr@2
|
232 |
* resolved error. Resolved text can be of any length. This version
|
williamr@2
|
233 |
* is for "normal" use.
|
williamr@2
|
234 |
*
|
williamr@2
|
235 |
* @param aError The error code to be resolved.
|
williamr@2
|
236 |
* @param aContext Optional context for error numbers. If the aContext
|
williamr@2
|
237 |
* parameter is not passed to the function, it uses the default value
|
williamr@2
|
238 |
* ECtxAutomatic.
|
williamr@2
|
239 |
* @return the error text for the resolved error. "System error" (in
|
williamr@2
|
240 |
* English localisation) is returned when error code is not known. For
|
williamr@2
|
241 |
* unknown errors blank error flag (flags are defined in
|
williamr@2
|
242 |
* textresolver.hrh) is also set to hide errors without proper
|
williamr@2
|
243 |
* explanation. There is no limit on how long the resolved string
|
williamr@2
|
244 |
* can be.
|
williamr@2
|
245 |
*/
|
williamr@2
|
246 |
IMPORT_C const TDesC& ResolveErrorString(
|
williamr@2
|
247 |
TInt aError,
|
williamr@2
|
248 |
TErrorContext aContext = ECtxAutomatic);
|
williamr@2
|
249 |
|
williamr@2
|
250 |
private:
|
williamr@2
|
251 |
|
williamr@2
|
252 |
virtual TInt ResourceForError(TInt aError);
|
williamr@2
|
253 |
virtual void LoadResourceFilesL();
|
williamr@2
|
254 |
|
williamr@2
|
255 |
// Construction
|
williamr@2
|
256 |
CTextResolver(CCoeEnv& aEnv);
|
williamr@2
|
257 |
CTextResolver();
|
williamr@2
|
258 |
void ConstructL();
|
williamr@2
|
259 |
|
williamr@2
|
260 |
// Utility
|
williamr@2
|
261 |
void FindFullPathOfResourceFile(TFileName& aResFile) const;
|
williamr@2
|
262 |
void ReadResourcesToArraysL(TInt& aError, TInt& aTextId);
|
williamr@2
|
263 |
void Reset();
|
williamr@2
|
264 |
void PrepareReaderLC(TResourceReader& reader);
|
williamr@2
|
265 |
|
williamr@2
|
266 |
// returns NULL if fails
|
williamr@2
|
267 |
HBufC* ReadUnicodeString(const TInt& aTextId);
|
williamr@2
|
268 |
|
williamr@2
|
269 |
// returns false if any memory allocation fails or initial values
|
williamr@2
|
270 |
// of necessary pointers are NULL, indicating alloc failure earlier.
|
williamr@2
|
271 |
TBool AddContextAndSeparator(TErrorContext aContext);
|
williamr@2
|
272 |
|
williamr@2
|
273 |
private:
|
williamr@2
|
274 |
|
williamr@2
|
275 |
CCoeEnv* iCoe;
|
williamr@2
|
276 |
RResourceFile iRFile;
|
williamr@2
|
277 |
TInt iRDSupport;
|
williamr@2
|
278 |
TInt iBaseResourceFileOffset;
|
williamr@2
|
279 |
CArrayFix<TInt>* iStartError;
|
williamr@2
|
280 |
CArrayFix<TInt>* iAppTexts;
|
williamr@2
|
281 |
CArrayPtr<CErrorResourceIdArray>* iErrorTexts;
|
williamr@2
|
282 |
CArrayPtr<CErrorResourceFlagArray>* iFlags;
|
williamr@2
|
283 |
HBufC* iTextBuffer;
|
williamr@2
|
284 |
HBufC* iAppNameText;
|
williamr@2
|
285 |
HBufC* iContextSeparator;
|
williamr@2
|
286 |
RFs iFs;
|
williamr@2
|
287 |
TPtrC iTruncatedTextPointer;
|
williamr@2
|
288 |
};
|
williamr@2
|
289 |
|
williamr@2
|
290 |
#endif
|
williamr@2
|
291 |
|
williamr@2
|
292 |
// End of File
|