|
1 /* |
|
2 * Copyright (c) 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: UI State Listener |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <ctsydomainpskeys.h> |
|
20 |
|
21 // User includes |
|
22 #include "xnappuiadapter.h" |
|
23 #include "xnuistatelistener.h" |
|
24 |
|
25 // ============================ LOCAL FUNCTIONS ================================ |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CXnUiStateListener::NewL() |
|
31 // Two-phased constructor. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CXnUiStateListener* CXnUiStateListener::NewL( CXnAppUiAdapter& aAdapter ) |
|
35 { |
|
36 CXnUiStateListener* self = CXnUiStateListener::NewLC( aAdapter ); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CXnUiStateListener::NewLC() |
|
43 // Two-phased constructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CXnUiStateListener* CXnUiStateListener::NewLC( CXnAppUiAdapter& aAdapter ) |
|
47 { |
|
48 CXnUiStateListener* self = new( ELeave ) CXnUiStateListener( aAdapter ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CXnUiStateListener::CXnUiStateListener() |
|
56 // C++ default constructor |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CXnUiStateListener::CXnUiStateListener( CXnAppUiAdapter& aAdapter ) |
|
60 : iAppUiAdapter( aAdapter ), iLightStatus( CHWRMLight::ELightStatusUnknown ) |
|
61 { |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CXnUiStateListener::~CXnUiStateListener() |
|
66 // C++ default destructor. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CXnUiStateListener::~CXnUiStateListener() |
|
70 { |
|
71 iUiStateObservers.Reset(); |
|
72 iResourceChangeObservers.Reset(); |
|
73 |
|
74 iAppUiAdapter.StatusPane()->SetObserver( NULL ); |
|
75 CCoeEnv::Static()->RemoveMessageMonitorObserver( *this ); |
|
76 |
|
77 delete iLightObserver; |
|
78 delete iCallStateObserver; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CXnUiStateListener::ConstructL() |
|
83 // 2nd phase constructor |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void CXnUiStateListener::ConstructL() |
|
87 { |
|
88 iLightObserver = CHWRMLight::NewL( this ); |
|
89 |
|
90 iCallStateObserver = CXnPropertySubscriber::NewL( KPSUidCtsyCallInformation, |
|
91 KCTsyCallState, *this ); |
|
92 |
|
93 iAppUiAdapter.StatusPane()->SetObserver( this ); |
|
94 |
|
95 CCoeEnv::Static()->AddMessageMonitorObserverL( *this ); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CXnUiStateListener::AddObserver() |
|
100 // Adds MXnUiStateObserver |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 void CXnUiStateListener::AddObserver( const MXnUiStateObserver& aObserver ) |
|
104 { |
|
105 if ( iUiStateObservers.InsertInAddressOrder( &aObserver ) == KErrNone ) |
|
106 { |
|
107 MXnUiStateObserver& observer( |
|
108 const_cast< MXnUiStateObserver & >( aObserver) ); |
|
109 |
|
110 if ( iForegroundStatus != MXnUiStateObserver::EUnknown ) |
|
111 { |
|
112 observer.NotifyForegroundChanged( iForegroundStatus ); |
|
113 } |
|
114 |
|
115 observer.NotifyInCallStateChaged( iInCallState ); |
|
116 observer.NotifyLightStatusChanged( |
|
117 iLightStatus == CHWRMLight::ELightOn ? ETrue : EFalse ); |
|
118 } |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CXnUiStateListener::RemoveObserver() |
|
123 // Removes MXnUiStateObserver |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CXnUiStateListener::RemoveObserver( const MXnUiStateObserver& aObserver ) |
|
127 { |
|
128 TInt index( iUiStateObservers.Find( &aObserver ) ); |
|
129 |
|
130 if ( index != KErrNotFound ) |
|
131 { |
|
132 iUiStateObservers.Remove( index ); |
|
133 } |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CXnUiStateListener::AddObserver() |
|
138 // Adds MXnUiResourceChangeObserver |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CXnUiStateListener::AddObserver( |
|
142 const MXnUiResourceChangeObserver& aObserver ) |
|
143 { |
|
144 iResourceChangeObservers.InsertInAddressOrder( &aObserver ); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CXnUiStateListener::RemoveObserver() |
|
149 // Removes MXnUiResourceChangeObserver |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CXnUiStateListener::RemoveObserver( |
|
153 const MXnUiResourceChangeObserver& aObserver ) |
|
154 { |
|
155 TInt index( iResourceChangeObservers.Find( &aObserver ) ); |
|
156 |
|
157 if ( index != KErrNotFound ) |
|
158 { |
|
159 iResourceChangeObservers.Remove( index ); |
|
160 } |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CXnUiStateListener::HandleResourceChangeL() |
|
165 // |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CXnUiStateListener::HandleResourceChangeL( TInt aType ) |
|
169 { |
|
170 MXnUiStateObserver::TForegroundStatus status( iForegroundStatus ); |
|
171 |
|
172 if ( aType == KEikMessageFadeAllWindows ) |
|
173 { |
|
174 if ( iForegroundStatus != MXnUiStateObserver::EBackground ) |
|
175 { |
|
176 iForegroundStatus = MXnUiStateObserver::EPartialForeground; |
|
177 } |
|
178 } |
|
179 else if ( aType == KEikMessageUnfadeWindows ) |
|
180 { |
|
181 if ( iForegroundType == KAknFullOrPartialForegroundGained ) |
|
182 { |
|
183 if ( iAppUiAdapter.IsPartialForeground() ) |
|
184 { |
|
185 iForegroundStatus = MXnUiStateObserver::EPartialForeground; |
|
186 } |
|
187 else |
|
188 { |
|
189 iForegroundStatus = MXnUiStateObserver::EForeground; |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 if ( status != iForegroundStatus ) |
|
195 { |
|
196 for ( TInt i = 0; i < iUiStateObservers.Count(); i++ ) |
|
197 { |
|
198 iUiStateObservers[i]-> |
|
199 NotifyForegroundChanged( iForegroundStatus ); |
|
200 } |
|
201 } |
|
202 |
|
203 for ( TInt i = 0; i < iResourceChangeObservers.Count(); i++ ) |
|
204 { |
|
205 iResourceChangeObservers[i]->NotifyResourceChanged( aType ); |
|
206 } |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CXnUiStateListener::MonitorWsMessage() |
|
211 // |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void CXnUiStateListener::MonitorWsMessage( const TWsEvent& aEvent ) |
|
215 { |
|
216 TInt type( aEvent.Type() ); |
|
217 |
|
218 MXnUiStateObserver::TForegroundStatus status( iForegroundStatus ); |
|
219 |
|
220 if ( type == KAknFullOrPartialForegroundGained ) |
|
221 { |
|
222 iForegroundType = type; |
|
223 |
|
224 if ( iAppUiAdapter.IsPartialForeground() ) |
|
225 { |
|
226 iForegroundStatus = MXnUiStateObserver::EPartialForeground; |
|
227 } |
|
228 else |
|
229 { |
|
230 iForegroundStatus = MXnUiStateObserver::EForeground; |
|
231 } |
|
232 } |
|
233 else if ( type == KAknFullOrPartialForegroundLost ) |
|
234 { |
|
235 iForegroundType = type; |
|
236 |
|
237 iForegroundStatus = MXnUiStateObserver::EBackground; |
|
238 } |
|
239 else if ( type == EEventFocusLost ) |
|
240 { |
|
241 iForegroundStatus = MXnUiStateObserver::EBackground; |
|
242 } |
|
243 else if ( type == EEventFocusGained ) |
|
244 { |
|
245 if ( iForegroundType == KAknFullOrPartialForegroundGained ) |
|
246 { |
|
247 if ( iAppUiAdapter.IsPartialForeground() ) |
|
248 { |
|
249 iForegroundStatus = MXnUiStateObserver::EPartialForeground; |
|
250 } |
|
251 else |
|
252 { |
|
253 iForegroundStatus = MXnUiStateObserver::EForeground; |
|
254 } |
|
255 } |
|
256 } |
|
257 |
|
258 if ( status != iForegroundStatus ) |
|
259 { |
|
260 for ( TInt i = 0; i < iUiStateObservers.Count(); i++ ) |
|
261 { |
|
262 iUiStateObservers[i]-> |
|
263 NotifyForegroundChanged( iForegroundStatus ); |
|
264 } |
|
265 } |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CXnUiStateListener::HandleStatusPaneSizeChange() |
|
270 // |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void CXnUiStateListener::HandleStatusPaneSizeChange() |
|
274 { |
|
275 for ( TInt i = 0; i < iResourceChangeObservers.Count(); i++ ) |
|
276 { |
|
277 iResourceChangeObservers[i]->NotifyStatusPaneSizeChanged(); |
|
278 } |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CXnUiStateListener::LightStatusChanged() |
|
283 // |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 void CXnUiStateListener::LightStatusChanged( TInt aTarget, |
|
287 CHWRMLight::TLightStatus aStatus ) |
|
288 { |
|
289 if ( aTarget == CHWRMLight::EPrimaryDisplay ) |
|
290 { |
|
291 if ( ( aStatus == CHWRMLight::ELightOn || |
|
292 aStatus == CHWRMLight::ELightOff ) && |
|
293 aStatus != iLightStatus ) |
|
294 { |
|
295 iLightStatus = aStatus; |
|
296 |
|
297 for ( TInt i = 0; i < iUiStateObservers.Count(); i++ ) |
|
298 { |
|
299 iUiStateObservers[i]-> |
|
300 NotifyLightStatusChanged( |
|
301 iLightStatus == CHWRMLight::ELightOn ? ETrue : EFalse ); |
|
302 } |
|
303 } |
|
304 } |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CXnUiStateListener::PropertyChangedL() |
|
309 // |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 void CXnUiStateListener::PropertyChangedL( const TUint32 aKey, |
|
313 const TInt aValue ) |
|
314 { |
|
315 if ( aKey == KCTsyCallState ) |
|
316 { |
|
317 TBool active( aValue > EPSCTsyCallStateNone ); |
|
318 |
|
319 if( iInCallState != active ) |
|
320 { |
|
321 iInCallState = active; |
|
322 |
|
323 for ( TInt i = 0; i < iUiStateObservers.Count(); i++ ) |
|
324 { |
|
325 iUiStateObservers[i]->NotifyInCallStateChaged( iInCallState ); |
|
326 } |
|
327 } |
|
328 } |
|
329 } |
|
330 |
|
331 // End of file |