1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This file implements class CFSMailBrand. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 |
|
20 //<qmail> |
|
21 #include <nmcommonheaders.h> |
|
22 //</qmail> |
|
23 |
|
24 #include <barsread.h> |
|
25 //<qmail> Commented out in Qmail |
|
26 //#include <AknIconUtils.h> |
|
27 //</qmail> |
|
28 #include <gulicon.h> |
|
29 #include <centralrepository.h> |
|
30 //<cmail> |
|
31 //<qmail> Commented out in Qmail |
|
32 //#include "freestyleemailcenrepkeys.h" |
|
33 //</qmail> |
|
34 //</cmail> |
|
35 |
|
36 #include "CFSMailBrand.h" |
|
37 |
|
38 const TInt KElementArrayGranularity = 5; |
|
39 //<qmail> Commented out in Qmail |
|
40 //const TInt KMaxStringLenFromCenrep = 256; |
|
41 //</qmail> |
|
42 const TInt KMaxDesLen = 256; |
|
43 _LIT(KSpace, " "); |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CFSMailBrand::NewL |
|
46 // ----------------------------------------------------------------------------- |
|
47 CFSMailBrand* CFSMailBrand::NewL( TResourceReader& aReader, TBool aIsWhiteLabel ) |
|
48 { |
|
49 NM_FUNCTION; |
|
50 |
|
51 CFSMailBrand* brManager = CFSMailBrand::NewLC(aReader, aIsWhiteLabel); |
|
52 CleanupStack:: Pop(brManager); |
|
53 return brManager; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CFSMailBrand::NewLC |
|
58 // ----------------------------------------------------------------------------- |
|
59 CFSMailBrand* CFSMailBrand::NewLC( TResourceReader& aReader, TBool aIsWhiteLabel ) |
|
60 { |
|
61 NM_FUNCTION; |
|
62 |
|
63 CFSMailBrand* self = new ( ELeave ) CFSMailBrand(); |
|
64 CleanupStack::PushL( self ); |
|
65 if ( aIsWhiteLabel ) |
|
66 { |
|
67 self->ConstructFromCenrepL( ); |
|
68 } |
|
69 else |
|
70 { |
|
71 self->ConstructFromResourceL( aReader ); |
|
72 } |
|
73 return self; |
|
74 } |
|
75 |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CFSMailBrand::ConstructFromCenrepL |
|
79 // ----------------------------------------------------------------------------- |
|
80 void CFSMailBrand::ConstructFromCenrepL( ) |
|
81 { |
|
82 NM_FUNCTION; |
|
83 |
|
84 /* |
|
85 TBuf<KMaxStringLenFromCenrep> tBuf; // Temporary buffer |
|
86 HBufC* mailboxName; |
|
87 |
|
88 iGraphicElements = new ( ELeave ) |
|
89 CArrayFixSeg< TBrandedGraphic >( KElementArrayGranularity ); |
|
90 |
|
91 iTextElements = new ( ELeave ) |
|
92 CArrayFixSeg< TBrandedText >( KElementArrayGranularity ); |
|
93 |
|
94 iTexts = new ( ELeave ) CDesCArraySeg( KElementArrayGranularity ); |
|
95 |
|
96 CRepository* repository = NULL; |
|
97 TRAPD( ret, repository = CRepository::NewL( KFreestyleEmailCenRep )); |
|
98 if ( ret == KErrNone ) |
|
99 { |
|
100 CleanupStack::PushL( repository ); |
|
101 TInt err_count = 0; |
|
102 // Read all WLB related parameters from Central Repository |
|
103 TInt err = repository->Get( KFreestyleWLBBrandIdMatchString, tBuf ); |
|
104 HBufC* buf = tBuf.AllocL(); |
|
105 iBrandMatchStrings.AppendL(buf); |
|
106 if ( err != KErrNone ) |
|
107 { |
|
108 err_count++; |
|
109 } |
|
110 err = repository->Get( KFreestyleWLBMailboxName, tBuf ); |
|
111 mailboxName = tBuf.AllocLC(); |
|
112 if ( err != KErrNone ) |
|
113 { |
|
114 err_count++; |
|
115 } |
|
116 err = repository->Get( KFreestyleWLBMIFFilePathWithTargetFilename, tBuf ); |
|
117 iIconFilePath = tBuf.AllocL(); |
|
118 if ( err != KErrNone ) |
|
119 { |
|
120 err_count++; |
|
121 } |
|
122 if ( err_count == 0 ) |
|
123 { |
|
124 // Create WLB graphic elements |
|
125 TBrandedGraphic newMailboxIconElement; |
|
126 newMailboxIconElement.iElementId = ( TFSBrandElement ) EFSMailboxIcon; |
|
127 err = repository->Get( KFreestyleWLBMailboxIconID, newMailboxIconElement.iIconId ); |
|
128 if ( err != KErrNone ) |
|
129 newMailboxIconElement.iIconId = 0x4000; // Use default if Cenrep read fails |
|
130 newMailboxIconElement.iMaskId = newMailboxIconElement.iIconId + 1; |
|
131 iGraphicElements->AppendL( newMailboxIconElement ); |
|
132 |
|
133 TBrandedText newMailboxNameElement; |
|
134 newMailboxNameElement.iElementId = ( TFSBrandElement) EFSMailboxName; |
|
135 iTexts->AppendL( *mailboxName ); |
|
136 newMailboxNameElement.iText.Set( iTexts->MdcaPoint( iTexts->Count() - 1 ) ); |
|
137 iTextElements->AppendL( newMailboxNameElement ); |
|
138 } |
|
139 CleanupStack::PopAndDestroy( mailboxName ); |
|
140 CleanupStack::PopAndDestroy( repository ); |
|
141 } |
|
142 */ |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CFSMailBrand::ConstructFromResourceL |
|
147 // ----------------------------------------------------------------------------- |
|
148 void CFSMailBrand::ConstructFromResourceL( TResourceReader& aReader ) |
|
149 { |
|
150 NM_FUNCTION; |
|
151 |
|
152 // read icon filepath |
|
153 iIconFilePath = aReader.ReadHBufCL(); |
|
154 |
|
155 // read match strings |
|
156 TInt count = aReader.ReadInt16(); |
|
157 for ( TInt i = 0; i < count; i++ ) |
|
158 { |
|
159 iBrandMatchStrings.AppendL(aReader.ReadHBufCL()); |
|
160 } |
|
161 |
|
162 // read graphics |
|
163 iGraphicElements = new ( ELeave ) |
|
164 CArrayFixSeg< TBrandedGraphic >( KElementArrayGranularity ); |
|
165 count = aReader.ReadInt16(); |
|
166 for ( TInt i = 0; i < count; i++ ) |
|
167 { |
|
168 TBrandedGraphic newElement; |
|
169 newElement.iElementId = ( TFSBrandElement ) aReader.ReadInt32(); |
|
170 newElement.iIconId = aReader.ReadInt32(); |
|
171 newElement.iMaskId = aReader.ReadInt32(); |
|
172 iGraphicElements->AppendL( newElement ); |
|
173 } |
|
174 |
|
175 // read texts |
|
176 iTexts = new ( ELeave ) CDesCArraySeg( KElementArrayGranularity ); |
|
177 iTextElements = new ( ELeave ) |
|
178 CArrayFixSeg< TBrandedText >( KElementArrayGranularity ); |
|
179 count = aReader.ReadInt16(); |
|
180 for ( TInt i = 0; i < count; i++ ) |
|
181 { |
|
182 TBrandedText newElement; |
|
183 newElement.iElementId = ( TFSBrandElement) aReader.ReadInt32(); |
|
184 HBufC* text = aReader.ReadTPtrC().AllocLC(); |
|
185 iTexts->AppendL( *text ); |
|
186 CleanupStack::PopAndDestroy( text ); |
|
187 newElement.iText.Set( iTexts->MdcaPoint( iTexts->Count() - 1 ) ); |
|
188 iTextElements->AppendL( newElement ); |
|
189 } |
|
190 |
|
191 // read colors |
|
192 iColorElements = new ( ELeave ) |
|
193 CArrayFixSeg< TBrandedColor >( KElementArrayGranularity ); |
|
194 count = aReader.ReadInt16(); |
|
195 for ( TInt i = 0; i < count; i++ ) |
|
196 { |
|
197 TBrandedColor newElement; |
|
198 newElement.iElementId = ( TFSBrandElement ) aReader.ReadInt32(); |
|
199 newElement.iColor.SetRed( aReader.ReadInt16() ); |
|
200 newElement.iColor.SetGreen( aReader.ReadInt16() ); |
|
201 newElement.iColor.SetBlue( aReader.ReadInt16() ); |
|
202 newElement.iColor.SetAlpha( aReader.ReadInt16() ); |
|
203 iColorElements->AppendL( newElement ); |
|
204 } |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CFSMailBrand::~CFSMailBrand() |
|
209 // ----------------------------------------------------------------------------- |
|
210 CFSMailBrand::~CFSMailBrand() |
|
211 { |
|
212 NM_FUNCTION; |
|
213 |
|
214 iBrandMatchStrings.ResetAndDestroy(); |
|
215 delete iIconFilePath; |
|
216 delete iGraphicElements; |
|
217 delete iTextElements; |
|
218 delete iColorElements; |
|
219 delete iTexts; |
|
220 delete iEmpty; |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CFSMailBrand::CFSMailBrand() |
|
225 // ----------------------------------------------------------------------------- |
|
226 CFSMailBrand::CFSMailBrand() |
|
227 { |
|
228 NM_FUNCTION; |
|
229 |
|
230 // prepare null empty descriptor |
|
231 iEmpty = HBufC::New(1); |
|
232 iEmpty->Des().Copy(KNullDesC()); |
|
233 |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CFSMailBrand::IsMatching |
|
238 // ----------------------------------------------------------------------------- |
|
239 TBool CFSMailBrand::IsMatching( const TDesC& aBrandId ) |
|
240 { |
|
241 NM_FUNCTION; |
|
242 const TChar KStar = '*'; |
|
243 TBool ret = EFalse; |
|
244 TInt intRet = 0; |
|
245 TInt count = iBrandMatchStrings.Count(); |
|
246 for( TInt i=0;i<count;i++ ) |
|
247 { |
|
248 TPtrC brandMatchStringPtr = *iBrandMatchStrings[i]; |
|
249 TInt matchPos = aBrandId.MatchC( *iBrandMatchStrings[i] ); |
|
250 if ( matchPos >= 0 ) |
|
251 { |
|
252 TPtrC rightPartPtr = aBrandId.Right( aBrandId.Length()-matchPos ); |
|
253 TChar isStar = brandMatchStringPtr[0]; |
|
254 TInt cut = 0; |
|
255 if ( isStar == KStar ) |
|
256 { |
|
257 cut = 1; |
|
258 } |
|
259 TPtrC matchString = brandMatchStringPtr.Right( brandMatchStringPtr.Length()-cut ); |
|
260 intRet = rightPartPtr.CompareC( matchString ); |
|
261 if ( intRet == 0 ) |
|
262 { |
|
263 ret = ETrue; |
|
264 } |
|
265 } |
|
266 } |
|
267 return ret; |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CFSMailBrand::GetText |
|
272 // ----------------------------------------------------------------------------- |
|
273 TDesC& CFSMailBrand::GetText( TFSBrandElement aElementId ) |
|
274 { |
|
275 NM_FUNCTION; |
|
276 |
|
277 TInt textCount( iTextElements->Count() ); |
|
278 |
|
279 for ( TInt i( 0 ); i < textCount; i++ ) |
|
280 { |
|
281 if ( iTextElements->At( i ).iElementId == aElementId ) |
|
282 { |
|
283 return iTextElements->At( i ).iText; |
|
284 } |
|
285 } |
|
286 |
|
287 return *iEmpty; |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CFSMailBrand::GetColor |
|
292 // ----------------------------------------------------------------------------- |
|
293 TInt CFSMailBrand::GetColor( TFSBrandElement aElementId, TRgb& aColor ) |
|
294 { |
|
295 NM_FUNCTION; |
|
296 |
|
297 TInt colorCount( iColorElements->Count() ); |
|
298 |
|
299 for ( TInt i( 0 ); i < colorCount; i++ ) |
|
300 { |
|
301 if ( iColorElements->At( i ).iElementId == aElementId ) |
|
302 { |
|
303 aColor = iColorElements->At( i ).iColor; |
|
304 return KErrNone; |
|
305 } |
|
306 } |
|
307 |
|
308 return KErrNotFound; |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CFSMailBrand::GetGraphicL |
|
313 // ----------------------------------------------------------------------------- |
|
314 CGulIcon* CFSMailBrand::GetGraphicL( TFSBrandElement aElementId ) |
|
315 { |
|
316 NM_FUNCTION; |
|
317 |
|
318 TInt graphicsCount( iGraphicElements->Count() ); |
|
319 |
|
320 for ( TInt i( 0 ); i < graphicsCount; i++ ) |
|
321 { |
|
322 TBrandedGraphic element = iGraphicElements->At( i ); |
|
323 |
|
324 if ( element.iElementId == aElementId ) |
|
325 { |
|
326 CFbsBitmap* icon( NULL ); |
|
327 CFbsBitmap* mask( NULL ); |
|
328 |
|
329 if ( iIconFilePath == NULL ) |
|
330 { |
|
331 // If graphic element is found but no path is defined it is |
|
332 // deemed as an error situation. |
|
333 User::Leave( KErrNotFound ); |
|
334 } |
|
335 |
|
336 TFileName dllFileName; |
|
337 Dll::FileName( dllFileName ); |
|
338 TParse parse; |
|
339 User::LeaveIfError( parse.Set( *iIconFilePath, &dllFileName, NULL) ); |
|
340 TFileName iconFileName( parse.FullName() ); |
|
341 |
|
342 //<qmail> |
|
343 // Get icon and mask with above info |
|
344 /*AknIconUtils::CreateIconLC( icon, |
|
345 mask, |
|
346 iconFileName, |
|
347 element.iIconId, |
|
348 element.iMaskId );*/ |
|
349 //</qmail> |
|
350 CGulIcon* gulIcon = CGulIcon::NewL( icon, mask ); |
|
351 |
|
352 CleanupStack::Pop( 2 ); // icon, mask |
|
353 |
|
354 return gulIcon; |
|
355 } |
|
356 } |
|
357 |
|
358 return NULL; |
|
359 } |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CFSMailBrand::GetGraphicIdsL |
|
363 // ----------------------------------------------------------------------------- |
|
364 TInt CFSMailBrand::GetGraphicIdsL( TFSBrandElement aElementId, |
|
365 TDes& aIconIds) |
|
366 { |
|
367 NM_FUNCTION; |
|
368 |
|
369 aIconIds.Zero(); |
|
370 TInt graphicsCount( iGraphicElements->Count() ); |
|
371 |
|
372 for ( TInt i( 0 ); i < graphicsCount; i++ ) |
|
373 { |
|
374 TBrandedGraphic element = iGraphicElements->At( i ); |
|
375 |
|
376 if ( element.iElementId == aElementId ) |
|
377 { |
|
378 if ( iIconFilePath == NULL ) |
|
379 { |
|
380 // If graphic element is found but no path is defined it is |
|
381 // deemed as an error situation. |
|
382 User::Leave( KErrNotFound ); |
|
383 } |
|
384 |
|
385 TFileName dllFileName; |
|
386 Dll::FileName( dllFileName ); |
|
387 TParse parse; |
|
388 User::LeaveIfError( parse.Set( *iIconFilePath, &dllFileName, NULL) ); |
|
389 TFileName iconFileName( parse.FullName() ); |
|
390 |
|
391 TBuf<KMaxDesLen> id; |
|
392 aIconIds.Copy(iconFileName); |
|
393 aIconIds.Append(KSpace); |
|
394 id.Num(element.iIconId); |
|
395 aIconIds.Append(id); |
|
396 aIconIds.Append(KSpace); |
|
397 id.Num(element.iMaskId); |
|
398 aIconIds.Append(id); |
|
399 |
|
400 return KErrNone; |
|
401 } |
|
402 } |
|
403 |
|
404 return KErrNotFound; |
|
405 } |
|
406 |
|