|
1 /* |
|
2 * Copyright (c) 2008-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: Handles & propogates UI state change notifications. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 * @internal reviewed 24/08/2007 by D Holland |
|
22 */ |
|
23 |
|
24 // Class header |
|
25 #include "glxtv.h" |
|
26 |
|
27 // External includes |
|
28 #include <w32std.h> // for TWsVisibilityChangedEvent |
|
29 |
|
30 // INTERNAL INCLUDES |
|
31 #include <glxlog.h> // for debug logging |
|
32 #include <glxtracer.h> // for debug logging |
|
33 #include <glxpanic.h> // for Gallery panic codes |
|
34 #include <glxtvconstants.h> // for ETvConnectionChanged, TV heights |
|
35 #include <centralrepository.h> // for CRepository |
|
36 #ifdef __MARM |
|
37 #include <GSServerEngine.h> |
|
38 #endif |
|
39 |
|
40 // GLXTVOUT INCLUDES |
|
41 #include "mglxtvobserver.h" // for MGlxTvObserver |
|
42 #include "glxwindowvisibilitymonitor.h" // for CGlxWindowVisibilityMonitor |
|
43 #include "glxtvconnectionmonitor.h" // for CGlxTvConnectionMonitor |
|
44 |
|
45 const TUid KCRUidTvoutSettings = {0x1020730B}; |
|
46 |
|
47 using namespace glxTvOut; |
|
48 |
|
49 /** |
|
50 * CGlxTvOutCenRepMonitor |
|
51 * CGlxTv conainted class for observing changes in central |
|
52 * repository TV aspect Ratio value |
|
53 * @author Loughlin Spollen |
|
54 */ |
|
55 NONSHARABLE_CLASS( CGlxTv::CGlxTvOutCenRepMonitor ) |
|
56 : public CActive |
|
57 { |
|
58 public: // Constructors and destructor |
|
59 /** |
|
60 * Symbian Constructor. |
|
61 * @param The TV Observer |
|
62 * @param The central repository |
|
63 * @return constructed object |
|
64 */ |
|
65 static CGlxTvOutCenRepMonitor* NewL(MGlxTvObserver& aTvObserver, |
|
66 CRepository& aRepository); |
|
67 |
|
68 /** |
|
69 * Destructor. |
|
70 */ |
|
71 ~CGlxTvOutCenRepMonitor(); |
|
72 |
|
73 private: |
|
74 /** |
|
75 * C++ constructor. |
|
76 * @param The TV Observer |
|
77 * @param The central repository |
|
78 * @return constructed object |
|
79 */ |
|
80 CGlxTvOutCenRepMonitor(MGlxTvObserver& aTvObserver, |
|
81 CRepository& aRepository); |
|
82 /** |
|
83 * 2nd phase constructor |
|
84 */ |
|
85 void ConstructL(); |
|
86 |
|
87 protected: // from CActive |
|
88 /** |
|
89 * @ref CActive::RunL |
|
90 */ |
|
91 void RunL(); |
|
92 |
|
93 /** |
|
94 * @ref CActive::DoCancel |
|
95 */ |
|
96 void DoCancel(); |
|
97 |
|
98 /** |
|
99 * @ref CActive::RunError |
|
100 */ |
|
101 TInt RunError(TInt aError); |
|
102 |
|
103 private: |
|
104 |
|
105 // Not Owned: the Glx TV observer |
|
106 MGlxTvObserver& iTvObserver; |
|
107 |
|
108 // Not Owned: the central repository API |
|
109 CRepository& iRepository; |
|
110 |
|
111 TUint iSettingsTVAspectRatio; |
|
112 // the central repository identifier |
|
113 TUid iRepositoryUid; |
|
114 }; |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // Two-phased constructor. |
|
121 // ----------------------------------------------------------------------------- |
|
122 CGlxTv::CGlxTvOutCenRepMonitor* CGlxTv::CGlxTvOutCenRepMonitor::NewL |
|
123 ( MGlxTvObserver& aTvObserver, |
|
124 CRepository& aRepository ) |
|
125 { |
|
126 TRACER("CGlxTv::CGlxTvOutCenRepMonitor::NewL()"); |
|
127 |
|
128 CGlxTvOutCenRepMonitor* self |
|
129 = new(ELeave) CGlxTvOutCenRepMonitor( aTvObserver, aRepository ); |
|
130 CleanupStack::PushL( self ); |
|
131 self->ConstructL(); |
|
132 CleanupStack::Pop( self ); |
|
133 return self; |
|
134 } |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // C++ constructor. |
|
141 // ----------------------------------------------------------------------------- |
|
142 inline CGlxTv::CGlxTvOutCenRepMonitor::CGlxTvOutCenRepMonitor |
|
143 ( MGlxTvObserver& aTvObserver, |
|
144 CRepository& aRepository ) |
|
145 : CActive( EPriorityStandard ), |
|
146 iTvObserver ( aTvObserver ), |
|
147 iRepository( aRepository ) |
|
148 { |
|
149 TRACER("CGlxTv::CGlxTvOutCenRepMonitor::CGlxTvOutCenRepMonitor()"); |
|
150 } |
|
151 |
|
152 |
|
153 |
|
154 // ---------------------------------------------------------------------------- |
|
155 // Symbian 2nd phase constructor |
|
156 // ---------------------------------------------------------------------------- |
|
157 void CGlxTv::CGlxTvOutCenRepMonitor::ConstructL() |
|
158 { |
|
159 TRACER("CGlxTv::CGlxTvOutCenRepMonitor::ConstructL"); |
|
160 CActiveScheduler::Add( this ); |
|
161 #ifdef __MARM |
|
162 CGSServerEngine* gsServerEngine= CGSServerEngine::NewLC(); |
|
163 iSettingsTVAspectRatio = gsServerEngine->AspectRatioL(); |
|
164 CleanupStack::Pop(gsServerEngine); |
|
165 #else |
|
166 iSettingsTVAspectRatio = 0; |
|
167 #endif |
|
168 } |
|
169 |
|
170 |
|
171 |
|
172 // ---------------------------------------------------------------------------- |
|
173 // Destructor |
|
174 // ---------------------------------------------------------------------------- |
|
175 CGlxTv::CGlxTvOutCenRepMonitor::~CGlxTvOutCenRepMonitor() |
|
176 { |
|
177 TRACER("CGlxTv::~CGlxTvOutCenRepMonitor()"); |
|
178 Cancel(); |
|
179 } |
|
180 |
|
181 |
|
182 |
|
183 // ---------------------------------------------------------------------------- |
|
184 // CGlxTvOutCenRepMonitor::RunL |
|
185 // From class CActive. |
|
186 // ---------------------------------------------------------------------------- |
|
187 void CGlxTv::CGlxTvOutCenRepMonitor::RunL() |
|
188 { |
|
189 TRACER("CGlxTv::CGlxTvOutCenRepMonitor::RunL"); |
|
190 // Check for errors |
|
191 User::LeaveIfError( iStatus.Int() ); |
|
192 GLX_LOG_INFO("CGlxTvOutCenRepMonitor - RunL completed with Err Code"); |
|
193 User::LeaveIfError( iRepository.NotifyRequest( iSettingsTVAspectRatio, iStatus ) ); |
|
194 if (!IsActive()) |
|
195 { |
|
196 SetActive(); |
|
197 iTvObserver.HandleTvStatusChangedL( ETvConnectionChanged ); |
|
198 } |
|
199 } |
|
200 |
|
201 |
|
202 |
|
203 // ---------------------------------------------------------------------------- |
|
204 // CGlxTvOutCenRepMonitor::DoCancel |
|
205 // From class CActive. |
|
206 // ---------------------------------------------------------------------------- |
|
207 void CGlxTv::CGlxTvOutCenRepMonitor::DoCancel() |
|
208 { |
|
209 TRACER("CGlxTv::CGlxTvOutCenRepMonitor::DoCancel()"); |
|
210 iRepository.NotifyCancel( iSettingsTVAspectRatio ); |
|
211 } |
|
212 |
|
213 |
|
214 |
|
215 //----------------------------------------------------------------------------- |
|
216 // CGlxTvOutCenRepMonitor::RunError |
|
217 // From class CActive. |
|
218 //----------------------------------------------------------------------------- |
|
219 // |
|
220 TInt CGlxTv::CGlxTvOutCenRepMonitor::RunError( TInt /*aError*/ ) |
|
221 { |
|
222 TRACER("CGlxTv::CGlxTvOutCenRepMonitor::RunError()"); |
|
223 return KErrNone; |
|
224 } |
|
225 |
|
226 |
|
227 //----------------------------------------------------------------------------- |
|
228 // Return new object |
|
229 //----------------------------------------------------------------------------- |
|
230 // |
|
231 EXPORT_C CGlxTv* CGlxTv::NewL( MGlxTvObserver& aTvObserver ) |
|
232 { |
|
233 TRACER("CGlxTv::NewL()"); |
|
234 CGlxTv* self = new (ELeave) CGlxTv( aTvObserver ); |
|
235 CleanupStack::PushL( self ); |
|
236 self->ConstructL(); |
|
237 CleanupStack::Pop( self ); |
|
238 return self; |
|
239 } |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 //----------------------------------------------------------------------------- |
|
245 // Destructor |
|
246 //----------------------------------------------------------------------------- |
|
247 // |
|
248 EXPORT_C CGlxTv::~CGlxTv() |
|
249 { |
|
250 TRACER("CGlxTv::~CGlxTv()"); |
|
251 StopMonitoringEnvironment(); |
|
252 delete iTvConnectionMonitor; |
|
253 } |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 //----------------------------------------------------------------------------- |
|
259 // Default C++ constructor |
|
260 //----------------------------------------------------------------------------- |
|
261 // |
|
262 CGlxTv::CGlxTv( MGlxTvObserver& aTvObserver ) : iTvObserver( aTvObserver ), |
|
263 iAspectRatio( KErrUnknown ) |
|
264 { |
|
265 TRACER("CGlxTv::CGlxTv()"); |
|
266 } |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 //----------------------------------------------------------------------------- |
|
272 // Symbian second phase constructor |
|
273 //----------------------------------------------------------------------------- |
|
274 // |
|
275 void CGlxTv::ConstructL() |
|
276 { |
|
277 TRACER("CGlxTv::ConstructL()"); |
|
278 // Don't create the visibility monitor until the TV Out cable is connected |
|
279 |
|
280 // Owned: The TV connection monitor |
|
281 iTvConnectionMonitor = CGlxTvConnectionMonitor::NewL( *this ); |
|
282 |
|
283 if ( iTvConnectionMonitor->IsConnected() ) |
|
284 { |
|
285 // Start monitoring the environment for changes |
|
286 MonitorEnvironmentL(); |
|
287 |
|
288 // Calculate the TV Out screen buffer size |
|
289 CalcTvScreenSzL(); |
|
290 } |
|
291 } |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 //----------------------------------------------------------------------------- |
|
297 // returns the TV screen size |
|
298 //----------------------------------------------------------------------------- |
|
299 // |
|
300 EXPORT_C TSize CGlxTv::ScreenSizeL() const |
|
301 { |
|
302 TRACER("CGlxTv::ScreenSizeL()"); |
|
303 return iSzInPixels; |
|
304 } |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 //----------------------------------------------------------------------------- |
|
310 // Is the analog TV Connected |
|
311 //----------------------------------------------------------------------------- |
|
312 // |
|
313 EXPORT_C TBool CGlxTv::IsConnected() const |
|
314 { |
|
315 TRACER("CGlxTv::IsConnected()"); |
|
316 return iTvConnectionMonitor->IsConnected(); |
|
317 } |
|
318 |
|
319 |
|
320 //----------------------------------------------------------------------------- |
|
321 // Is the HDMI TV Connected |
|
322 //----------------------------------------------------------------------------- |
|
323 // |
|
324 EXPORT_C TBool CGlxTv::IsHDMIConnected() const |
|
325 { |
|
326 TRACER("CGlxTv::IsHDMIConnected()"); |
|
327 return iTvConnectionMonitor->IsHDMIConnected(); |
|
328 } |
|
329 |
|
330 //----------------------------------------------------------------------------- |
|
331 // Is the TV widescreen |
|
332 //----------------------------------------------------------------------------- |
|
333 // |
|
334 EXPORT_C TBool CGlxTv::IsWidescreen() const |
|
335 { |
|
336 TRACER("CGlxTv::IsWidescreen()"); |
|
337 return iAspectRatio == KGlxTvAspectWide; |
|
338 } |
|
339 |
|
340 |
|
341 //----------------------------------------------------------------------------- |
|
342 // From class MGlxWindowVisibilityObserver. |
|
343 // Called when window becomes fully visible or not visible. |
|
344 //----------------------------------------------------------------------------- |
|
345 // |
|
346 void CGlxTv::HandleWindowVisibilityChangedL( TTvChangeType aChangeType ) |
|
347 { |
|
348 TRACER("CGlxTv::HandleWindowVisibilityChangedL()"); |
|
349 iTvObserver.HandleTvStatusChangedL( aChangeType ); |
|
350 } |
|
351 |
|
352 |
|
353 |
|
354 //----------------------------------------------------------------------------- |
|
355 // From class MGlxTvConnectionObserver. |
|
356 // Called when TV connection state changes |
|
357 //----------------------------------------------------------------------------- |
|
358 // |
|
359 void CGlxTv::HandleTvConnectionStatusChangedL(TTvChangeType aChangeType) |
|
360 { |
|
361 TRACER("CGlxTv::HandleTvConnectionStatusChangedL()"); |
|
362 |
|
363 if (iTvConnectionMonitor->IsConnected()) |
|
364 { |
|
365 // Start monitoring the environment for changes |
|
366 MonitorEnvironmentL(); |
|
367 // Calculate the TV Out screen buffer |
|
368 CalcTvScreenSzL(); |
|
369 } |
|
370 else |
|
371 { |
|
372 StopMonitoringEnvironment(); |
|
373 } |
|
374 |
|
375 iTvObserver.HandleTvStatusChangedL(aChangeType); |
|
376 } |
|
377 |
|
378 //----------------------------------------------------------------------------- |
|
379 // Retrieve the TV display aspect ratio |
|
380 //----------------------------------------------------------------------------- |
|
381 // |
|
382 void CGlxTv::CalcTvScreenSzL() |
|
383 { |
|
384 TRACER("CGlxTv::CalcTvScreenSzL()"); |
|
385 |
|
386 // Retrieve the aspect ratio and the settings info from CenRep |
|
387 iAspectRatio = KErrNotFound; |
|
388 |
|
389 #ifdef __MARM |
|
390 CGSServerEngine* gsServerEngine = CGSServerEngine::NewLC(); |
|
391 iAspectRatio = gsServerEngine->AspectRatioL(); |
|
392 CleanupStack::Pop(gsServerEngine); |
|
393 User::LeaveIfError( iAspectRatio ); |
|
394 #else |
|
395 iAspectRatio = 0; |
|
396 #endif |
|
397 // note: Constants are defined in the GSServerEngine.cpp and not exported |
|
398 // they are defined locally in glxtvconstants.h |
|
399 switch( iAspectRatio ) |
|
400 { |
|
401 case KGlxTvAspectWide: |
|
402 { |
|
403 iSzInPixels = TSize ( KGlxTvOutWidthWide, KGlxTvOutHeightWide) ; |
|
404 break; |
|
405 } |
|
406 case KGlxTvAspectNormal: |
|
407 { |
|
408 iSzInPixels = TSize ( KGlxTvOutWidth, KGlxTvOutHeight ); |
|
409 break; |
|
410 } |
|
411 default: |
|
412 { |
|
413 User::Leave(KErrUnknown); |
|
414 } |
|
415 } |
|
416 } |
|
417 |
|
418 |
|
419 //----------------------------------------------------------------------------- |
|
420 // From class MonitorEnvironmentL. |
|
421 // Called when TV connection state changes to connected |
|
422 //----------------------------------------------------------------------------- |
|
423 // |
|
424 void CGlxTv::MonitorEnvironmentL() |
|
425 { |
|
426 TRACER("CGlxTv::MonitorEnvironmentL()"); |
|
427 |
|
428 // Instantiate the central repository |
|
429 if (!iCenRep) |
|
430 { |
|
431 // The Uid is hardcoded here as the hrh file giving us the Uid has been depricated and |
|
432 // moved to a private folder |
|
433 iCenRep = CRepository::NewL( KCRUidTvoutSettings ); |
|
434 } |
|
435 |
|
436 // Monitor changes to the aspect ratio in the central repository |
|
437 if (!iTvDisplayAspectRatioMonitor) |
|
438 { |
|
439 iTvDisplayAspectRatioMonitor |
|
440 = CGlxTvOutCenRepMonitor::NewL( iTvObserver, *iCenRep ); |
|
441 } |
|
442 |
|
443 // create window visibility monitoring object |
|
444 if ( !iWindowVisibilityMonitor ) |
|
445 { |
|
446 iWindowVisibilityMonitor = |
|
447 CGlxWindowVisibilityMonitor::NewL( *this ); |
|
448 } |
|
449 } |
|
450 |
|
451 |
|
452 //----------------------------------------------------------------------------- |
|
453 // StopMonitoringEnvironment(). |
|
454 // Called when TV connection state changes to disconnected |
|
455 //----------------------------------------------------------------------------- |
|
456 // |
|
457 void CGlxTv::StopMonitoringEnvironment() |
|
458 { |
|
459 TRACER("CGlxTv::StopMonitoringEnvironment()"); |
|
460 delete iTvDisplayAspectRatioMonitor; // destroy before iCenRep - must cancel |
|
461 iTvDisplayAspectRatioMonitor = NULL; // outstanding requests |
|
462 if (iWindowVisibilityMonitor) |
|
463 { |
|
464 iWindowVisibilityMonitor->Close(); |
|
465 } |
|
466 delete iWindowVisibilityMonitor; |
|
467 iWindowVisibilityMonitor = NULL; |
|
468 delete iCenRep; |
|
469 iCenRep = NULL; |
|
470 } |
|
471 |
|
472 |
|
473 // End of file |