|
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* aGSServerEngine= CGSServerEngine::NewLC(); |
|
163 iSettingsTVAspectRatio = aGSServerEngine->AspectRatioL(); |
|
164 CleanupStack::Pop(aGSServerEngine); |
|
165 #else |
|
166 iSettingsTVAspectRatio = 0; |
|
167 #endif |
|
168 // Commenting out code for request notification as these doesnt work fine, |
|
169 // would be soon updated with latest api's to support aspectration chnages. |
|
170 // Request notification when the user changes cenrep values |
|
171 // TInt err = iRepository.NotifyRequest( iSettingsTVAspectRatio, iStatus ); |
|
172 // if (!(KErrNone ==err ||KErrAlreadyExists ==err)) |
|
173 // { |
|
174 // RDebug::Printf("## Error code in CGlxTv::CGlxTvOutCenRepMonitor::ConstructL() is %d",err); |
|
175 // User::Leave(err); |
|
176 // } |
|
177 |
|
178 // SetActive(); |
|
179 } |
|
180 |
|
181 |
|
182 |
|
183 // ---------------------------------------------------------------------------- |
|
184 // Destructor |
|
185 // ---------------------------------------------------------------------------- |
|
186 CGlxTv::CGlxTvOutCenRepMonitor::~CGlxTvOutCenRepMonitor() |
|
187 { |
|
188 TRACER("CGlxTv::~CGlxTvOutCenRepMonitor()"); |
|
189 Cancel(); |
|
190 } |
|
191 |
|
192 |
|
193 |
|
194 // ---------------------------------------------------------------------------- |
|
195 // CGlxTvOutCenRepMonitor::RunL |
|
196 // From class CActive. |
|
197 // ---------------------------------------------------------------------------- |
|
198 void CGlxTv::CGlxTvOutCenRepMonitor::RunL() |
|
199 { |
|
200 TRACER("CGlxTv::CGlxTvOutCenRepMonitor::RunL"); |
|
201 // Check for errors |
|
202 User::LeaveIfError( iStatus.Int() ); |
|
203 GLX_LOG_INFO("CGlxTvOutCenRepMonitor - RunL completed with Err Code"); |
|
204 User::LeaveIfError( iRepository.NotifyRequest( iSettingsTVAspectRatio, iStatus ) ); |
|
205 if (!IsActive()) |
|
206 { |
|
207 SetActive(); |
|
208 iTvObserver.HandleTvStatusChangedL( ETvConnectionChanged ); |
|
209 } |
|
210 } |
|
211 |
|
212 |
|
213 |
|
214 // ---------------------------------------------------------------------------- |
|
215 // CGlxTvOutCenRepMonitor::DoCancel |
|
216 // From class CActive. |
|
217 // ---------------------------------------------------------------------------- |
|
218 void CGlxTv::CGlxTvOutCenRepMonitor::DoCancel() |
|
219 { |
|
220 TRACER("CGlxTv::CGlxTvOutCenRepMonitor::DoCancel()"); |
|
221 iRepository.NotifyCancel( iSettingsTVAspectRatio ); |
|
222 } |
|
223 |
|
224 |
|
225 |
|
226 //----------------------------------------------------------------------------- |
|
227 // CGlxTvOutCenRepMonitor::RunError |
|
228 // From class CActive. |
|
229 //----------------------------------------------------------------------------- |
|
230 // |
|
231 TInt CGlxTv::CGlxTvOutCenRepMonitor::RunError( TInt /*aError*/ ) |
|
232 { |
|
233 TRACER("CGlxTv::CGlxTvOutCenRepMonitor::RunError()"); |
|
234 return KErrNone; |
|
235 } |
|
236 |
|
237 |
|
238 //----------------------------------------------------------------------------- |
|
239 // Return new object |
|
240 //----------------------------------------------------------------------------- |
|
241 // |
|
242 EXPORT_C CGlxTv* CGlxTv::NewL( MGlxTvObserver& aTvObserver ) |
|
243 { |
|
244 TRACER("CGlxTv::NewL()"); |
|
245 CGlxTv* self = new (ELeave) CGlxTv( aTvObserver ); |
|
246 CleanupStack::PushL( self ); |
|
247 self->ConstructL(); |
|
248 CleanupStack::Pop( self ); |
|
249 return self; |
|
250 } |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 //----------------------------------------------------------------------------- |
|
256 // Destructor |
|
257 //----------------------------------------------------------------------------- |
|
258 // |
|
259 EXPORT_C CGlxTv::~CGlxTv() |
|
260 { |
|
261 TRACER("CGlxTv::~CGlxTv()"); |
|
262 StopMonitoringEnvironment(); |
|
263 delete iTvConnectionMonitor; |
|
264 } |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 //----------------------------------------------------------------------------- |
|
270 // Default C++ constructor |
|
271 //----------------------------------------------------------------------------- |
|
272 // |
|
273 CGlxTv::CGlxTv( MGlxTvObserver& aTvObserver ) : iTvObserver( aTvObserver ), |
|
274 iAspectRatio( KErrUnknown ) |
|
275 { |
|
276 TRACER("CGlxTv::CGlxTv()"); |
|
277 } |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 //----------------------------------------------------------------------------- |
|
283 // Symbian second phase constructor |
|
284 //----------------------------------------------------------------------------- |
|
285 // |
|
286 void CGlxTv::ConstructL() |
|
287 { |
|
288 TRACER("CGlxTv::ConstructL()"); |
|
289 // Don't create the visibility monitor until the TV Out cable is connected |
|
290 |
|
291 // Owned: The TV connection monitor |
|
292 iTvConnectionMonitor = CGlxTvConnectionMonitor::NewL( *this ); |
|
293 |
|
294 if ( iTvConnectionMonitor->IsConnected() ) |
|
295 { |
|
296 // Start monitoring the environment for changes |
|
297 MonitorEnvironmentL(); |
|
298 |
|
299 // Calculate the TV Out screen buffer size |
|
300 CalcTvScreenSzL(); |
|
301 } |
|
302 } |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 //----------------------------------------------------------------------------- |
|
308 // returns the TV screen size |
|
309 //----------------------------------------------------------------------------- |
|
310 // |
|
311 EXPORT_C TSize CGlxTv::ScreenSizeL() const |
|
312 { |
|
313 TRACER("CGlxTv::ScreenSizeL()"); |
|
314 return iSzInPixels; |
|
315 } |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 //----------------------------------------------------------------------------- |
|
321 // Is the analog TV Connected |
|
322 //----------------------------------------------------------------------------- |
|
323 // |
|
324 EXPORT_C TBool CGlxTv::IsConnected() const |
|
325 { |
|
326 TRACER("CGlxTv::IsConnected()"); |
|
327 return iTvConnectionMonitor->IsConnected(); |
|
328 } |
|
329 |
|
330 |
|
331 //----------------------------------------------------------------------------- |
|
332 // Is the HDMI TV Connected |
|
333 //----------------------------------------------------------------------------- |
|
334 // |
|
335 EXPORT_C TBool CGlxTv::IsHDMIConnected() const |
|
336 { |
|
337 TRACER("CGlxTv::IsHDMIConnected()"); |
|
338 return iTvConnectionMonitor->IsHDMIConnected(); |
|
339 } |
|
340 |
|
341 //----------------------------------------------------------------------------- |
|
342 // Is the TV widescreen |
|
343 //----------------------------------------------------------------------------- |
|
344 // |
|
345 EXPORT_C TBool CGlxTv::IsWidescreen() const |
|
346 { |
|
347 TRACER("CGlxTv::IsWidescreen()"); |
|
348 return iAspectRatio == KGlxTvAspectWide; |
|
349 } |
|
350 |
|
351 |
|
352 //----------------------------------------------------------------------------- |
|
353 // From class MGlxWindowVisibilityObserver. |
|
354 // Called when window becomes fully visible or not visible. |
|
355 //----------------------------------------------------------------------------- |
|
356 // |
|
357 void CGlxTv::HandleWindowVisibilityChangedL( TTvChangeType aChangeType ) |
|
358 { |
|
359 TRACER("CGlxTv::HandleWindowVisibilityChangedL()"); |
|
360 iTvObserver.HandleTvStatusChangedL( aChangeType ); |
|
361 } |
|
362 |
|
363 |
|
364 |
|
365 //----------------------------------------------------------------------------- |
|
366 // From class MGlxTvConnectionObserver. |
|
367 // Called when TV connection state changes |
|
368 //----------------------------------------------------------------------------- |
|
369 // |
|
370 void CGlxTv::HandleTvConnectionStatusChangedL( ) |
|
371 { |
|
372 TRACER("CGlxTv::HandleTvConnectionStatusChangedL()"); |
|
373 |
|
374 if ( iTvConnectionMonitor->IsConnected() ) |
|
375 { |
|
376 // Start monitoring the environment for changes |
|
377 MonitorEnvironmentL(); |
|
378 // Calculate the TV Out screen buffer |
|
379 CalcTvScreenSzL(); |
|
380 } |
|
381 else |
|
382 { |
|
383 StopMonitoringEnvironment(); |
|
384 } |
|
385 iTvObserver.HandleTvStatusChangedL( ETvConnectionChanged ); |
|
386 } |
|
387 |
|
388 |
|
389 |
|
390 //----------------------------------------------------------------------------- |
|
391 // Retrieve the TV display aspect ratio |
|
392 //----------------------------------------------------------------------------- |
|
393 // |
|
394 void CGlxTv::CalcTvScreenSzL() |
|
395 { |
|
396 TRACER("CGlxTv::CalcTvScreenSzL()"); |
|
397 |
|
398 // Retrieve the aspect ratio and the settings info from CenRep |
|
399 iAspectRatio = KErrNotFound; |
|
400 |
|
401 #ifdef __MARM |
|
402 CGSServerEngine* aGSServerEngine = CGSServerEngine::NewLC(); |
|
403 iAspectRatio = aGSServerEngine->AspectRatioL(); |
|
404 CleanupStack::Pop(aGSServerEngine); |
|
405 User::LeaveIfError( iAspectRatio ); |
|
406 #else |
|
407 iAspectRatio = 0; |
|
408 #endif |
|
409 // note: Constants are defined in the GSServerEngine.cpp and not exported |
|
410 // they are defined locally in glxtvconstants.h |
|
411 switch( iAspectRatio ) |
|
412 { |
|
413 case KGlxTvAspectWide: |
|
414 { |
|
415 iSzInPixels = TSize ( KGlxTvOutWidthWide, KGlxTvOutHeightWide) ; |
|
416 break; |
|
417 } |
|
418 case KGlxTvAspectNormal: |
|
419 { |
|
420 iSzInPixels = TSize ( KGlxTvOutWidth, KGlxTvOutHeight ); |
|
421 break; |
|
422 } |
|
423 default: |
|
424 { |
|
425 User::Leave(KErrUnknown); |
|
426 } |
|
427 } |
|
428 } |
|
429 |
|
430 |
|
431 //----------------------------------------------------------------------------- |
|
432 // From class MonitorEnvironmentL. |
|
433 // Called when TV connection state changes to connected |
|
434 //----------------------------------------------------------------------------- |
|
435 // |
|
436 void CGlxTv::MonitorEnvironmentL() |
|
437 { |
|
438 TRACER("CGlxTv::MonitorEnvironmentL()"); |
|
439 |
|
440 // Instantiate the central repository |
|
441 if (!iCenRep) |
|
442 { |
|
443 // The Uid is hardcoded here as the hrh file giving us the Uid has been depricated and |
|
444 // moved to a private folder |
|
445 iCenRep = CRepository::NewL( KCRUidTvoutSettings ); |
|
446 } |
|
447 |
|
448 // Monitor changes to the aspect ratio in the central repository |
|
449 if (!iTvDisplayAspectRatioMonitor) |
|
450 { |
|
451 iTvDisplayAspectRatioMonitor |
|
452 = CGlxTvOutCenRepMonitor::NewL( iTvObserver, *iCenRep ); |
|
453 } |
|
454 |
|
455 // create window visibility monitoring object |
|
456 if ( !iWindowVisibilityMonitor ) |
|
457 { |
|
458 iWindowVisibilityMonitor = |
|
459 CGlxWindowVisibilityMonitor::NewL( *this ); |
|
460 } |
|
461 } |
|
462 |
|
463 |
|
464 //----------------------------------------------------------------------------- |
|
465 // StopMonitoringEnvironment(). |
|
466 // Called when TV connection state changes to disconnected |
|
467 //----------------------------------------------------------------------------- |
|
468 // |
|
469 void CGlxTv::StopMonitoringEnvironment() |
|
470 { |
|
471 TRACER("CGlxTv::StopMonitoringEnvironment()"); |
|
472 delete iTvDisplayAspectRatioMonitor; // destroy before iCenRep - must cancel |
|
473 iTvDisplayAspectRatioMonitor = NULL; // outstanding requests |
|
474 if (iWindowVisibilityMonitor) |
|
475 { |
|
476 iWindowVisibilityMonitor->Close(); |
|
477 } |
|
478 delete iWindowVisibilityMonitor; |
|
479 iWindowVisibilityMonitor = NULL; |
|
480 delete iCenRep; |
|
481 iCenRep = NULL; |
|
482 } |
|
483 |
|
484 |
|
485 // End of file |