1 /* |
|
2 * Copyright (c) 2008-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: Implements access to branding server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <coemain.h> |
|
20 #include <spentry.h> |
|
21 #include <mbsaccess.h> |
|
22 #include <AknsUtils.h> |
|
23 #include <cbsbitmap.h> |
|
24 #include <cbsfactory.h> |
|
25 #include <mbselement.h> |
|
26 #include <spsettings.h> |
|
27 #include <spproperty.h> |
|
28 #include <spdefinitions.h> |
|
29 |
|
30 #include "cchuipluginbrandinghandler.h" |
|
31 #include "cchuipluginiconfileprovider.h" |
|
32 |
|
33 _LIT8( KDefaultAppId, "xsp" ); |
|
34 _LIT8( KBrandedBitmapItemId, "service_passive_image_small" ); |
|
35 |
|
36 const TUint KIconWidth( 20 ); |
|
37 const TUint KIconHeight( 20 ); |
|
38 const TUint KBrandStringMaxLength( 255 ); |
|
39 |
|
40 |
|
41 // ======== MEMBER FUNCTIONS ======== |
|
42 |
|
43 CCchUiPluginBrandingHandler::CCchUiPluginBrandingHandler( |
|
44 CSPSettings& aSpSettings ): |
|
45 iSpSettings( aSpSettings ) |
|
46 { |
|
47 } |
|
48 |
|
49 void CCchUiPluginBrandingHandler::ConstructL() |
|
50 { |
|
51 } |
|
52 |
|
53 CCchUiPluginBrandingHandler* CCchUiPluginBrandingHandler::NewL( |
|
54 CSPSettings& aSpSettings ) |
|
55 { |
|
56 CCchUiPluginBrandingHandler* self = NewLC( aSpSettings ); |
|
57 CleanupStack::Pop( self ); |
|
58 return self; |
|
59 } |
|
60 |
|
61 CCchUiPluginBrandingHandler* CCchUiPluginBrandingHandler::NewLC( |
|
62 CSPSettings& aSpSettings ) |
|
63 { |
|
64 CCchUiPluginBrandingHandler* self = |
|
65 new (ELeave) CCchUiPluginBrandingHandler( aSpSettings ); |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL(); |
|
68 return self; |
|
69 } |
|
70 |
|
71 CCchUiPluginBrandingHandler::~CCchUiPluginBrandingHandler() |
|
72 { |
|
73 delete iFactory; |
|
74 iFactory = NULL; |
|
75 if ( iAccess ) |
|
76 { |
|
77 iAccess->Close(); |
|
78 } |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // Retrieves service icon. |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void CCchUiPluginBrandingHandler::RetrieveServiceIconL( |
|
86 TUint32 aServiceId, CFbsBitmap*& aBitmap, CFbsBitmap*& aMask ) |
|
87 { |
|
88 // start fetching of branding image |
|
89 // get structure containing the info needed to load brand image |
|
90 MBSElement* bitmapItem = NULL; |
|
91 |
|
92 // Access must be created and destroyed for each call since this is |
|
93 // common implementation for all services, otherwise brand data |
|
94 // fetching might fail or return data from another service. |
|
95 PrepareBrandingAccessL( aServiceId ); |
|
96 |
|
97 bitmapItem = iAccess->GetStructureL( KBrandedBitmapItemId() ); |
|
98 CleanupClosePushL( *bitmapItem ); |
|
99 |
|
100 // get info from the bitmap element |
|
101 const CBSBitmap& bsBitmap = bitmapItem->BitmapDataL(); |
|
102 |
|
103 RFile bitmapFile; |
|
104 CleanupClosePushL( bitmapFile ); |
|
105 |
|
106 // get the bitmap file from where we can load the bitmap |
|
107 iAccess->GetFileL( bsBitmap.BitmapFileId(), bitmapFile ); |
|
108 |
|
109 TInt err = KErrNotFound; |
|
110 CFbsBitmap* skinBitmap = NULL; |
|
111 |
|
112 // Try getting skinned images first |
|
113 if ( CCoeEnv::Static() ) |
|
114 { |
|
115 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
116 |
|
117 TAknsItemID itemId; |
|
118 itemId.Set( bsBitmap.SkinIdMajor(), bsBitmap.SkinIdMinor() ); |
|
119 |
|
120 TRAP( err, skinBitmap = AknsUtils::CreateBitmapL( skin, itemId ) ); |
|
121 } |
|
122 |
|
123 if ( err == KErrNotFound ) |
|
124 { |
|
125 // no skin bitmap found |
|
126 |
|
127 // icon server take ownership of icon file provider |
|
128 // File provider duplicates the file handle, close the original |
|
129 // Duplication needed because lifetime of image is different than |
|
130 // this file handle's. |
|
131 CCchUiPluginIconFileProvider* ifp = |
|
132 CCchUiPluginIconFileProvider::NewL( bitmapFile ); |
|
133 CleanupStack::PushL( ifp ); |
|
134 |
|
135 AknIconUtils::CreateIconLC( aBitmap, aMask, |
|
136 *ifp, |
|
137 bsBitmap.BitmapId(), |
|
138 bsBitmap.BitmapMaskId() ); |
|
139 CleanupStack::Pop( aMask ); |
|
140 CleanupStack::Pop( aBitmap ); |
|
141 CleanupStack::Pop( ifp ); |
|
142 } |
|
143 else if ( err ) |
|
144 { |
|
145 User::Leave( err ); |
|
146 } |
|
147 else |
|
148 { |
|
149 aBitmap = skinBitmap; |
|
150 aMask = NULL; |
|
151 } |
|
152 // Icons must be initialized with setsize in order to use them |
|
153 TSize size( KIconWidth, KIconHeight ); |
|
154 if ( aBitmap ) |
|
155 { |
|
156 AknIconUtils::SetSize( aBitmap, size ); |
|
157 } |
|
158 |
|
159 if ( aMask ) |
|
160 { |
|
161 AknIconUtils::SetSize( aMask, size ); |
|
162 } |
|
163 |
|
164 CleanupStack::PopAndDestroy( &bitmapFile ); |
|
165 CleanupStack::PopAndDestroy( bitmapItem ); |
|
166 ReleaseBrandingAccess(); |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // Prepares branding access. |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CCchUiPluginBrandingHandler::PrepareBrandingAccessL( TUint32 aServiceId ) |
|
174 { |
|
175 ReleaseBrandingAccess(); |
|
176 |
|
177 HBufC8* brandiId8 = HBufC8::NewLC( KBrandStringMaxLength ); |
|
178 TPtr8 brandiId8Ptr( brandiId8->Des() ); |
|
179 |
|
180 HBufC* brandId = HBufC::NewLC( KBrandStringMaxLength ); |
|
181 TPtr brandiIdPtr( brandId->Des() ); |
|
182 |
|
183 CSPProperty* idProperty = CSPProperty::NewLC(); |
|
184 iSpSettings.FindPropertyL( aServiceId, |
|
185 EPropertyBrandId, |
|
186 *idProperty ); |
|
187 if ( idProperty ) |
|
188 { |
|
189 idProperty->GetValue( brandiIdPtr ); |
|
190 brandiId8Ptr.Copy( brandiIdPtr ); |
|
191 } |
|
192 CleanupStack::PopAndDestroy( idProperty ); |
|
193 CleanupStack::PopAndDestroy( brandId ); |
|
194 |
|
195 // default to english |
|
196 TInt brandLanguage = ELangInternationalEnglish; |
|
197 CSPProperty* lanProperty = CSPProperty::NewLC(); |
|
198 iSpSettings.FindPropertyL( aServiceId, |
|
199 EPropertyBrandLanguage, |
|
200 *lanProperty ); |
|
201 if ( lanProperty ) |
|
202 { |
|
203 lanProperty->GetValue( brandLanguage ); |
|
204 brandLanguage = ((TLanguage) (brandLanguage)); |
|
205 } |
|
206 CleanupStack::PopAndDestroy( lanProperty ); |
|
207 |
|
208 iFactory = CBSFactory::NewL( brandiId8Ptr, KDefaultAppId ); |
|
209 iAccess = iFactory->CreateAccessL( brandiId8Ptr, |
|
210 ((TLanguage) ( brandLanguage )) ); |
|
211 CleanupStack::PopAndDestroy( brandiId8 ); |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // Releases branding access. |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void CCchUiPluginBrandingHandler::ReleaseBrandingAccess() |
|
219 { |
|
220 if ( iAccess ) |
|
221 { |
|
222 iAccess->Close(); |
|
223 iAccess = NULL; |
|
224 } |
|
225 delete iFactory; |
|
226 iFactory = NULL; |
|
227 } |
|
228 |
|
229 |
|