|
1 /* |
|
2 * Copyright (c) 2007-2009 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: The engine class of operator info plugin. Handles the |
|
15 * communication with Publish&Subscribe data. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <AknIconArray.h> // For itemsicon |
|
22 #include <gulicon.h> // For itemsicon |
|
23 #include <aknlayout.cdl.h> // For TAknWindowLineLayout |
|
24 #include <aknlayoutscalable_avkon.cdl.h> // For scalable layouts |
|
25 #include <AknUtils.h> |
|
26 #include <AknIconUtils.h> |
|
27 |
|
28 #include "caisatengine.h" |
|
29 #include "caisatnotifier.h" |
|
30 #include "mpluginapi.h" |
|
31 #include "tflogger.h" |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 // ----------------------------------------------------------------------------- |
|
35 // Default constructor |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CAiSatEngine::CAiSatEngine( MPluginAPI& aPlugin ) : |
|
39 iPlugin ( aPlugin ), |
|
40 iIcon( NULL ), |
|
41 iPreviousIconId( 0 ) |
|
42 { |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // Two-phased constructor. |
|
47 // Create instance of concrete ECOM interface implementation |
|
48 // ----------------------------------------------------------------------------- |
|
49 CAiSatEngine* CAiSatEngine::NewL( MPluginAPI& aPlugin ) |
|
50 { |
|
51 TFLOGSTRING( "CAiSatEngine::NewL called" ) |
|
52 |
|
53 CAiSatEngine* self = new( ELeave )CAiSatEngine( aPlugin ); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop( self ); |
|
57 |
|
58 TFLOGSTRING( "CAiSatEngine::NewL exits" ) |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // Destructor. |
|
64 // Closes the connection to the P&S and deletes |
|
65 // all the dynamic content. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CAiSatEngine::~CAiSatEngine() |
|
69 { |
|
70 TFLOGSTRING( "CAiSatEngine::~CAiSatEngine called" ) |
|
71 |
|
72 delete iNotifier; |
|
73 |
|
74 // Delete icon and null the pointer. |
|
75 delete iIcon; |
|
76 iIcon = NULL; |
|
77 |
|
78 iSatService.Close(); |
|
79 iSatSession.Close(); |
|
80 |
|
81 TFLOGSTRING( "CAiSatEngine::~CAiSatEngine exits" ) |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // Offers information about the content |
|
86 // Returns ETrue if there is content available, |
|
87 // EFalse if not. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 TBool CAiSatEngine::HasContent() |
|
91 { |
|
92 TFLOGSTRING( "CAiSatEngine::HasContent called - exits" ) |
|
93 return iNotifier->HasContent(); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // Retrieves the operator info text from RSatService |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void CAiSatEngine::ContentText( TPtrC& aString ) |
|
101 { |
|
102 TFLOGSTRING( "CAiSatEngine::ContentText called" ) |
|
103 |
|
104 iNotifier->GetIdleTextString( aString ); |
|
105 |
|
106 TFLOGSTRING( "CAiSatEngine::ContentText exits" ) |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // Offers the Idle Mode icon |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CAiSatEngine::ContentIconL( CGulIcon*& aGulIcon ) |
|
114 { |
|
115 TFLOGSTRING( "CAiSatEngine::ContentIconL called" ) |
|
116 |
|
117 // Active Idle framework will release the bitmap we would |
|
118 // publish. So a new bitmap should be created to avoid |
|
119 // destroying the bitmap owned by UAA. |
|
120 if ( iIcon ) |
|
121 { |
|
122 // The bitmap for publishing. |
|
123 CFbsBitmap* bitmapToPublish( NULL ); |
|
124 |
|
125 bitmapToPublish = new (ELeave) CFbsBitmap; |
|
126 CleanupStack::PushL( bitmapToPublish ); |
|
127 |
|
128 TSize size = iIcon->SizeInPixels(); |
|
129 TInt error = bitmapToPublish->Create( size, iIcon->DisplayMode() ); |
|
130 |
|
131 // Duplicate the bitmap owned by UAA into the new bitmap. |
|
132 if ( !error ) |
|
133 { |
|
134 error = DuplicateBitmap( bitmapToPublish, iIcon ); |
|
135 if ( !error ) |
|
136 { |
|
137 // Create a icon from the bitmap and publish it. |
|
138 aGulIcon = CGulIcon::NewL( bitmapToPublish ); |
|
139 CleanupStack::Pop( bitmapToPublish ); |
|
140 TFLOGSTRING( "CAiSatEngine::ContentIconL create GulIcon" ) |
|
141 } |
|
142 } |
|
143 if ( error ) |
|
144 { |
|
145 CleanupStack::PopAndDestroy( bitmapToPublish ); |
|
146 aGulIcon = NULL; |
|
147 } |
|
148 } |
|
149 TFLOGSTRING( "CAiSatEngine::ContentIconL exits" ) |
|
150 } |
|
151 |
|
152 //------------------------------------------------------------------------------ |
|
153 // Loads icon provided by SIM from RSatIcon |
|
154 //------------------------------------------------------------------------------ |
|
155 CFbsBitmap* CAiSatEngine::LoadIconL( TUint8 aIconId, |
|
156 RSatService::TSatIconQualifier aIconQualifier ) |
|
157 { |
|
158 TFLOGSTRING( "CAiSatEngine::LoadIconL called" ) |
|
159 CFbsBitmap* simIconBuffer( NULL ); |
|
160 |
|
161 // If icon allready has been got from SIM (via satIcon and SATServer) |
|
162 // Because mechanism for fetching icon is very slow, it has been |
|
163 // stored in class variable to make reasonable speed for |
|
164 // Active Idle refreshing. |
|
165 if ( RSatService::ESatIconSelfExplanatory == aIconQualifier || |
|
166 RSatService::ESatIconNotSelfExplanatory == aIconQualifier ) |
|
167 { |
|
168 TFLOGSTRING( "CAiSatEngine::LoadIconL having icon" ) |
|
169 RIconEf iconEf; |
|
170 CleanupClosePushL( iconEf ); |
|
171 |
|
172 // Get icon info |
|
173 iSatService.GetIconInfoL( aIconId, iconEf ); |
|
174 // Get the an available icon from info array. |
|
175 TInt infoCount( iconEf.Count() ); |
|
176 TInt error( KErrNotFound ); |
|
177 for ( TInt i = 0; i < infoCount && KErrNone != error; i++ ) |
|
178 { |
|
179 TRAP( error, simIconBuffer = iSatService.GetIconL( iconEf[i] ) ); |
|
180 } |
|
181 |
|
182 // Check whether the for loop ends without icon gotton. |
|
183 if ( error != KErrNone ) |
|
184 { |
|
185 TFLOGSTRING2( "CAiSatEngine::LoadIconL: error=%d",error ) |
|
186 simIconBuffer = NULL; |
|
187 } |
|
188 |
|
189 CleanupStack::PopAndDestroy( &iconEf ); |
|
190 } |
|
191 TFLOGSTRING( "CAiSatEngine::LoadIconL exit" ) |
|
192 return simIconBuffer; |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // Formulates response to SatIcon API |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 void CAiSatEngine::HandleNotifyL() |
|
200 { |
|
201 TFLOGSTRING( "CAiSatEngine::HandleNotifyL called" ) |
|
202 TUint8 id( iNotifier->IdleIconId() ); |
|
203 RSatService::TSatIconQualifier iconQualifier( |
|
204 iNotifier->IdleIconQualifier() ); |
|
205 |
|
206 if ( !HasContent() && RSatService::ESatIconNoIcon == iconQualifier ) |
|
207 { |
|
208 // Removal of text = No text and no icon |
|
209 TFLOGSTRING( "CAiSatNotifier::HasContent ETrue remove text success" ) |
|
210 SendSatResponseL( RSatService::ESATIdleSuccess ); |
|
211 } |
|
212 else |
|
213 { |
|
214 TFLOGSTRING2( "CAiSatEngine::HandleNotifyL Icon: %d", iconQualifier ) |
|
215 if ( RSatService::ESatIconNoIcon == iconQualifier) |
|
216 { |
|
217 TFLOGSTRING( "CAiSatEngine::HandleNotifyL ESatIconNoIcon" ) |
|
218 SendSatResponseL( RSatService::ESATIdleSuccess ); |
|
219 } |
|
220 else if ( RSatService::ESatIconSelfExplanatory == iconQualifier || |
|
221 RSatService::ESatIconNotSelfExplanatory == iconQualifier ) |
|
222 { |
|
223 SendSatResponseL( RSatService::ESATIdleSuccess ); |
|
224 TFLOGSTRING( "CAiSatEngine::HandleNotify icon & success resp" ) |
|
225 } |
|
226 else if ( RSatService::ESatIconNotSelfExplanatory != iconQualifier && |
|
227 RSatService::ESatIconNoIcon != iconQualifier ) |
|
228 { |
|
229 SendSatResponseL( RSatService::ESATIdleSuccessRequestedIconNotDisplayed ); |
|
230 TFLOGSTRING( "CAiSatEngine: KSATIdleSuccessRequestedIconNotDisplayed" ) |
|
231 } |
|
232 else |
|
233 { |
|
234 TFLOGSTRING( "CAiSatEngine::HandleNotifyL others" ) |
|
235 // Report error |
|
236 SendSatResponseL( RSatService::ESATIdleMeUnableToProcessCmd ); |
|
237 } |
|
238 } |
|
239 |
|
240 TFLOGSTRING( "CAiSatEngine::HandleNotify exit" ) |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // Get Idle mode data first, and load icon for publishing |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 void CAiSatEngine::PrepareIdleModeDataL( TBool& aDupIcon, TBool& aDupText ) |
|
248 { |
|
249 TFLOGSTRING( "CAiSatEngine::PrepareGetIdleModeDataL called" ) |
|
250 |
|
251 // Get icon Id, icon qualifier and text. |
|
252 iNotifier->GetIdleModeDataL( aDupIcon, aDupText ); |
|
253 |
|
254 // Load icon, and check whether it is the same with previous one. |
|
255 // if not, Load icon, otherwise, do nothing. |
|
256 TUint8 id ( iNotifier->IdleIconId() ); |
|
257 RSatService::TSatIconQualifier iconQualifier( |
|
258 iNotifier->IdleIconQualifier() ); |
|
259 |
|
260 if ( !( RSatService::ESatIconNoIcon == iconQualifier ) || |
|
261 !( id == iPreviousIconId && iIcon ) ) |
|
262 { |
|
263 TFLOGSTRING( "CAiSatEngine::PrepareIdleModeDataL load icon" ) |
|
264 delete iIcon; |
|
265 iIcon = NULL; |
|
266 |
|
267 // The bitmap is fetched from UAA. |
|
268 iIcon = LoadIconL( id, iconQualifier ); |
|
269 iPreviousIconId = id; |
|
270 } |
|
271 TFLOGSTRING( "CAiSatEngine::PrepareGetIdleModeDataL exits" ) |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // Symbian 2nd phase constructor can leave |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 void CAiSatEngine::ConstructL() |
|
279 { |
|
280 TFLOGSTRING( "CAiSatEngine::ConstructL called" ) |
|
281 |
|
282 iSatSession.ConnectL(); |
|
283 TFLOGSTRING( "CAiSatEngine::ConstructL connect sat session" ) |
|
284 |
|
285 iSatService.OpenL( iSatSession ); |
|
286 TFLOGSTRING( "CAiSatEngine::ConstructL open sat service" ) |
|
287 |
|
288 iNotifier = CAiSatNotifier::NewL( iPlugin, iSatService ); |
|
289 User::LeaveIfError( iNotifier->Start() ); |
|
290 |
|
291 TFLOGSTRING( "CAiSatEngine::ConstructL exits" ) |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------------------------- |
|
295 // Sends SAT response to RSatIcon |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 void CAiSatEngine::SendSatResponseL( |
|
299 const RSatService::TSATIdleResult& aResponse ) const |
|
300 { |
|
301 TFLOGSTRING( "CAiSatEngine::SendSatResponseL called") |
|
302 |
|
303 iSatService.SetIdleModeTextResponse( aResponse ); |
|
304 |
|
305 TFLOGSTRING( "CAiSatEngine::SendSatResponseL exits" ) |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // Duplicate a bitmap by copying memory. |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 TInt CAiSatEngine::DuplicateBitmap( const CFbsBitmap* aDestBmp, |
|
313 const CFbsBitmap* aSrcBmp ) |
|
314 { |
|
315 TFLOGSTRING( "CAiSatPlugin::DuplicateBitmap() called" ) |
|
316 |
|
317 // Get size and scan line length of the source bitmap. |
|
318 TSize size = aSrcBmp->SizeInPixels(); |
|
319 TInt scanLineLength = CFbsBitmap::ScanLineLength( |
|
320 size.iWidth, aSrcBmp->DisplayMode() ); |
|
321 TInt error( KErrNone ); |
|
322 // Copy the data area of the source bimap to the dest bitmap. |
|
323 if ( aSrcBmp && aSrcBmp->DataAddress() ) |
|
324 { |
|
325 TAny* bitmapData( NULL ); |
|
326 |
|
327 bitmapData = memcpy( |
|
328 (TAny*)aDestBmp->DataAddress(), |
|
329 (TAny*)aSrcBmp->DataAddress(), |
|
330 scanLineLength * size.iHeight ); |
|
331 |
|
332 if ( NULL == bitmapData ) |
|
333 { |
|
334 TFLOGSTRING( "CAiSatPlugin::DuplicateBitmap() \ |
|
335 Failed to copy memory data of bitmap." ) |
|
336 error = KErrBadHandle; |
|
337 } |
|
338 } |
|
339 |
|
340 TFLOGSTRING( "CAiSatPlugin::DuplicateBitmap() exits" ) |
|
341 |
|
342 return error; |
|
343 } |