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