1 /* |
|
2 * ============================================================================ |
|
3 * Name : hgteleportdevicestate.cpp |
|
4 * Part of : Hg Teleport |
|
5 * Description : Device state (touch mode, screen orientation) handler |
|
6 * Version : %version: sa1spcx1#14 % |
|
7 * |
|
8 * Copyright © 2008 Nokia. All rights reserved. |
|
9 * This material, including documentation and any related computer |
|
10 * programs, is protected by copyright controlled by Nokia. All |
|
11 * rights are reserved. Copying, including reproducing, storing, |
|
12 * adapting or translating, any or all of this material requires the |
|
13 * prior written consent of Nokia. This material also contains |
|
14 * confidential information which may not be disclosed to others |
|
15 * without the prior written consent of Nokia. |
|
16 * ============================================================================ |
|
17 * Template version: 4.2 |
|
18 */ |
|
19 |
|
20 #include "hgteleportdevicestate.h" |
|
21 #include <AknUtils.h> |
|
22 #include <hwrmdomainpskeys.h> |
|
23 |
|
24 #include "hgteleportapplogging.h" |
|
25 |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CHgTeleportDeviceState::NewL |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CHgTeleportDeviceState* CHgTeleportDeviceState::NewL() |
|
32 { |
|
33 CHgTeleportDeviceState* self = new ( ELeave ) CHgTeleportDeviceState; |
|
34 CleanupStack::PushL( self ); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop( self ); |
|
37 return self; |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CHgTeleportDeviceState::CHgTeleportDeviceState |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CHgTeleportDeviceState::CHgTeleportDeviceState() |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CHgTeleportDeviceState::ConstructL |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CHgTeleportDeviceState::ConstructL() |
|
53 { |
|
54 iFlipStatusObserver = new ( ELeave ) CHgPropertyListener(KPSUidHWRM, |
|
55 KHWRMFlipStatus, *this); |
|
56 // check if touch is enabled or not |
|
57 CheckTouchState(); |
|
58 // are we in portrait or landscape |
|
59 CheckOrientation(); |
|
60 // checks the qwerty input mode. |
|
61 CheckDeviceType(); |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CHgTeleportDeviceState::~CHgTeleportDeviceState |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CHgTeleportDeviceState::~CHgTeleportDeviceState() |
|
69 { |
|
70 iObservers.Close(); |
|
71 delete iFlipStatusObserver; |
|
72 } |
|
73 |
|
74 // -------------------------------------------------------------------------- |
|
75 // CHgTeleportDeviceState::HandleResourceChange |
|
76 // -------------------------------------------------------------------------- |
|
77 // |
|
78 void CHgTeleportDeviceState::HandleResourceChange( TInt aType ) |
|
79 { |
|
80 HGLOG_CONTEXT( HandleResourceChange, HGLOG_LOCAL ); |
|
81 HGLOG2_IN( "aType = %d (active count = %d)", aType, iResChangeActiveCount ); |
|
82 |
|
83 // increase function entrance count |
|
84 ++iResChangeActiveCount; |
|
85 // if we are still in a previous call then do nothing else |
|
86 if ( iResChangeActiveCount == 1 ) |
|
87 { |
|
88 // the active count may increase during execution of the body of the loop |
|
89 // (if some observers have active scheduler waits, for example) |
|
90 while ( iResChangeActiveCount > 0 ) |
|
91 { |
|
92 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
93 { |
|
94 HGLOG0( HGLOG_INFO, "dyn layout var switch" ); |
|
95 // This might be a screen orientation or touch-nontouch switch, |
|
96 // so let's check the situation and notify observers if needed. |
|
97 CheckTouchState(); |
|
98 CheckOrientation(); |
|
99 } |
|
100 else if ( aType == KAknsMessageSkinChange ) |
|
101 { |
|
102 HGLOG0( HGLOG_INFO, "skin change" ); |
|
103 NotifyObservers( MHgDeviceStateObserver::ESkin ); |
|
104 } |
|
105 --iResChangeActiveCount; |
|
106 } |
|
107 } |
|
108 |
|
109 HGLOG_OUT(); |
|
110 } |
|
111 |
|
112 // -------------------------------------------------------------------------- |
|
113 // CHgTeleportDeviceState::PropertyChanged |
|
114 // -------------------------------------------------------------------------- |
|
115 // |
|
116 void CHgTeleportDeviceState::PropertyChanged(TUid aCategory, TUint aKey) |
|
117 { |
|
118 HGLOG_CONTEXT( PropertyChanged, HGLOG_LOCAL ); |
|
119 HGLOG2_IN( "aKey = %d aNewValue = %d", aCategory, aKey ); |
|
120 CheckDeviceType(); |
|
121 HGLOG_OUT(); |
|
122 } |
|
123 |
|
124 // -------------------------------------------------------------------------- |
|
125 // CHgTeleportDeviceState::CheckTouchState |
|
126 // -------------------------------------------------------------------------- |
|
127 // |
|
128 void CHgTeleportDeviceState::CheckTouchState() |
|
129 { |
|
130 HGLOG_CONTEXT( CheckTouchState, HGLOG_LOCAL ); |
|
131 HGLOG_IN(); |
|
132 |
|
133 TTouchState oldValue = iTouchState; |
|
134 iTouchState = AknLayoutUtils::PenEnabled() ? ETouchEnabled : ETouchDisabled; |
|
135 if ( iTouchState != oldValue ) |
|
136 { |
|
137 NotifyObservers( MHgDeviceStateObserver::ETouchState ); |
|
138 } |
|
139 |
|
140 HGLOG1_OUT( "new value for iTouchState: %d", iTouchState ); |
|
141 } |
|
142 |
|
143 // -------------------------------------------------------------------------- |
|
144 // CHgTeleportDeviceState::CheckOrientation |
|
145 // -------------------------------------------------------------------------- |
|
146 // |
|
147 void CHgTeleportDeviceState::CheckOrientation() |
|
148 { |
|
149 HGLOG_CONTEXT( CheckOrientation, HGLOG_LOCAL ); |
|
150 HGLOG_IN(); |
|
151 |
|
152 TRect rect; |
|
153 AknLayoutUtils::LayoutMetricsRect ( AknLayoutUtils::EScreen, rect ); |
|
154 TOrientation oldValue = iOrientation; |
|
155 iOrientation = rect.Width() > rect.Height() ? ELandscape : EPortrait; |
|
156 if ( iOrientation != oldValue ) |
|
157 { |
|
158 NotifyObservers( MHgDeviceStateObserver::EOrientation ); |
|
159 } |
|
160 |
|
161 HGLOG1_OUT( "new value for iOrientation: %d", iOrientation ); |
|
162 } |
|
163 |
|
164 // -------------------------------------------------------------------------- |
|
165 // CHgTeleportDeviceState::DeviceType |
|
166 // -------------------------------------------------------------------------- |
|
167 // |
|
168 void CHgTeleportDeviceState::CheckDeviceType() |
|
169 { |
|
170 HGLOG_CONTEXT( CheckQwerty, HGLOG_LOCAL ); |
|
171 HGLOG_IN(); |
|
172 |
|
173 TInt oldDeviceType = iDeviceType; |
|
174 TInt value( 0 ); |
|
175 if( RProperty::Get( KPSUidHWRM, KHWRMFlipStatus, value ) == KErrNone ) |
|
176 { |
|
177 iDeviceType = (value == EPSHWRMFlipOpen ? EHybrid : EFullTouch); |
|
178 } |
|
179 |
|
180 if( iDeviceType != oldDeviceType ) |
|
181 { |
|
182 NotifyObservers( MHgDeviceStateObserver::EDeviceType); |
|
183 } |
|
184 |
|
185 HGLOG1_OUT( "new value for iDeviceType: %d", iDeviceType ); |
|
186 } |
|
187 |
|
188 // -------------------------------------------------------------------------- |
|
189 // CHgTeleportDeviceState::TouchState |
|
190 // -------------------------------------------------------------------------- |
|
191 // |
|
192 CHgTeleportDeviceState::TTouchState CHgTeleportDeviceState::TouchState() const |
|
193 { |
|
194 return iTouchState; |
|
195 } |
|
196 |
|
197 // -------------------------------------------------------------------------- |
|
198 // CHgTeleportDeviceState::Orientation |
|
199 // -------------------------------------------------------------------------- |
|
200 // |
|
201 CHgTeleportDeviceState::TOrientation CHgTeleportDeviceState::Orientation() const |
|
202 { |
|
203 return iOrientation; |
|
204 } |
|
205 |
|
206 // -------------------------------------------------------------------------- |
|
207 // CHgTeleportDeviceState::Qwerty |
|
208 // -------------------------------------------------------------------------- |
|
209 // |
|
210 CHgTeleportDeviceState::TDeviceType CHgTeleportDeviceState::DeviceType() const |
|
211 { |
|
212 return iDeviceType; |
|
213 } |
|
214 |
|
215 // -------------------------------------------------------------------------- |
|
216 // CHgTeleportDeviceState::ObserverIdentity |
|
217 // -------------------------------------------------------------------------- |
|
218 // |
|
219 TBool CHgTeleportDeviceState::ObserverIdentity( const SObserver& aA, |
|
220 const SObserver& aB ) |
|
221 { |
|
222 return aA.iObserver == aB.iObserver; |
|
223 } |
|
224 |
|
225 // -------------------------------------------------------------------------- |
|
226 // CHgTeleportDeviceState::AddDeviceStateObserverL |
|
227 // -------------------------------------------------------------------------- |
|
228 // |
|
229 void CHgTeleportDeviceState::AddObserverL( MHgDeviceStateObserver& aObserver, |
|
230 TInt aMask ) |
|
231 { |
|
232 iObservers.AppendL( SObserver( aMask, &aObserver ) ); |
|
233 } |
|
234 |
|
235 // -------------------------------------------------------------------------- |
|
236 // CHgTeleportDeviceState::RemoveObserver |
|
237 // -------------------------------------------------------------------------- |
|
238 // |
|
239 void CHgTeleportDeviceState::RemoveObserver( MHgDeviceStateObserver& aObserver ) |
|
240 { |
|
241 for ( ; ; ) |
|
242 { |
|
243 TInt pos = iObservers.Find( SObserver( MHgDeviceStateObserver::EAny, |
|
244 &aObserver ), ObserverIdentity ); |
|
245 if ( pos >= 0 ) |
|
246 { |
|
247 iObservers.Remove( pos ); |
|
248 } |
|
249 else |
|
250 { |
|
251 break; |
|
252 } |
|
253 } |
|
254 } |
|
255 |
|
256 // -------------------------------------------------------------------------- |
|
257 // CHgTeleportDeviceState::NotifyObservers |
|
258 // -------------------------------------------------------------------------- |
|
259 // |
|
260 void CHgTeleportDeviceState::NotifyObservers( |
|
261 MHgDeviceStateObserver::TChangeType aType ) |
|
262 { |
|
263 for ( TInt i = 0, ie = iObservers.Count(); i != ie; ++i ) |
|
264 { |
|
265 const SObserver& obs( iObservers[i] ); |
|
266 if ( obs.iMask & aType ) |
|
267 { |
|
268 obs.iObserver->HandleDeviceStateChanged( aType ); |
|
269 } |
|
270 } |
|
271 } |
|
272 |
|
273 |
|
274 // end of file |
|