photosgallery/viewframework/tvout/src/glxtv.cpp
changeset 0 4e91876724a2
child 4 57d388cc48c1
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     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 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 //-----------------------------------------------------------------------------
       
   333 // Is the TV widescreen
       
   334 //-----------------------------------------------------------------------------
       
   335 //
       
   336 EXPORT_C TBool CGlxTv::IsWidescreen() const
       
   337     {
       
   338     TRACER("CGlxTv::IsWidescreen()");
       
   339     return iAspectRatio == KGlxTvAspectWide;
       
   340     }
       
   341     
       
   342     
       
   343 //-----------------------------------------------------------------------------
       
   344 // From class MGlxWindowVisibilityObserver.
       
   345 // Called when window becomes fully visible or not visible.
       
   346 //-----------------------------------------------------------------------------
       
   347 //
       
   348 void CGlxTv::HandleWindowVisibilityChangedL( TTvChangeType aChangeType )
       
   349     {
       
   350     TRACER("CGlxTv::HandleWindowVisibilityChangedL()");
       
   351     iTvObserver.HandleTvStatusChangedL( aChangeType );
       
   352     }
       
   353     
       
   354     
       
   355     
       
   356 //-----------------------------------------------------------------------------
       
   357 // From class MGlxTvConnectionObserver.
       
   358 // Called when TV connection state changes
       
   359 //-----------------------------------------------------------------------------
       
   360 //
       
   361 void CGlxTv::HandleTvConnectionStatusChangedL( )
       
   362     {
       
   363     TRACER("CGlxTv::HandleTvConnectionStatusChangedL()");
       
   364 
       
   365     if ( iTvConnectionMonitor->IsConnected() )
       
   366         {
       
   367         // Start monitoring the environment for changes
       
   368         MonitorEnvironmentL();
       
   369         // Calculate the TV Out screen buffer
       
   370         CalcTvScreenSzL();
       
   371         }
       
   372     else
       
   373         {
       
   374         StopMonitoringEnvironment();
       
   375         }
       
   376     iTvObserver.HandleTvStatusChangedL( ETvConnectionChanged );
       
   377     }
       
   378     
       
   379         
       
   380    
       
   381 //-----------------------------------------------------------------------------
       
   382 // Retrieve the TV display aspect ratio
       
   383 //-----------------------------------------------------------------------------
       
   384 //
       
   385 void CGlxTv::CalcTvScreenSzL()
       
   386     {
       
   387     TRACER("CGlxTv::CalcTvScreenSzL()");
       
   388 
       
   389     // Retrieve the aspect ratio and the settings info from CenRep        
       
   390     iAspectRatio  = KErrNotFound;
       
   391    
       
   392 #ifdef __MARM
       
   393     CGSServerEngine* aGSServerEngine = CGSServerEngine::NewLC();
       
   394     iAspectRatio = aGSServerEngine->AspectRatioL();
       
   395     CleanupStack::Pop(aGSServerEngine);
       
   396 	User::LeaveIfError( iAspectRatio );
       
   397 #else
       
   398 	iAspectRatio = 0;
       
   399 #endif
       
   400     // note: Constants are defined in the GSServerEngine.cpp and not exported
       
   401     // they are defined locally in glxtvconstants.h
       
   402     switch( iAspectRatio )
       
   403         {
       
   404         case KGlxTvAspectWide:
       
   405             {
       
   406             iSzInPixels = TSize ( KGlxTvOutWidthWide, KGlxTvOutHeightWide) ;
       
   407             break;
       
   408             }
       
   409         case KGlxTvAspectNormal:
       
   410             {
       
   411             iSzInPixels = TSize ( KGlxTvOutWidth, KGlxTvOutHeight );
       
   412             break;
       
   413             }
       
   414         default:
       
   415             {
       
   416             User::Leave(KErrUnknown);
       
   417             }
       
   418         }
       
   419 	}
       
   420     
       
   421 
       
   422 //-----------------------------------------------------------------------------
       
   423 // From class MonitorEnvironmentL.
       
   424 // Called when TV connection state changes to connected
       
   425 //-----------------------------------------------------------------------------
       
   426 //
       
   427 void CGlxTv::MonitorEnvironmentL()
       
   428     {
       
   429     TRACER("CGlxTv::MonitorEnvironmentL()");
       
   430   
       
   431     // Instantiate the central repository
       
   432     if (!iCenRep)
       
   433         {
       
   434         // The Uid is hardcoded here as the hrh file giving us the Uid has been depricated and 
       
   435         // moved to a private folder
       
   436         iCenRep = CRepository::NewL( KCRUidTvoutSettings );
       
   437         }
       
   438     
       
   439     // Monitor changes to the aspect ratio in the central repository
       
   440     if (!iTvDisplayAspectRatioMonitor)    
       
   441         {
       
   442         iTvDisplayAspectRatioMonitor 
       
   443                     = CGlxTvOutCenRepMonitor::NewL( iTvObserver, *iCenRep );
       
   444         }
       
   445     
       
   446     // create window visibility monitoring object
       
   447     if ( !iWindowVisibilityMonitor )
       
   448         {
       
   449         iWindowVisibilityMonitor = 
       
   450                                 CGlxWindowVisibilityMonitor::NewL( *this );
       
   451         }
       
   452     }
       
   453 
       
   454     
       
   455 //-----------------------------------------------------------------------------
       
   456 // StopMonitoringEnvironment().
       
   457 // Called when TV connection state changes to disconnected
       
   458 //-----------------------------------------------------------------------------
       
   459 //
       
   460 void CGlxTv::StopMonitoringEnvironment()
       
   461     {
       
   462     TRACER("CGlxTv::StopMonitoringEnvironment()");
       
   463     delete iTvDisplayAspectRatioMonitor; // destroy before iCenRep - must cancel 
       
   464     iTvDisplayAspectRatioMonitor = NULL; // outstanding requests
       
   465     if (iWindowVisibilityMonitor)
       
   466         {
       
   467         iWindowVisibilityMonitor->Close();
       
   468         }
       
   469     delete iWindowVisibilityMonitor;
       
   470     iWindowVisibilityMonitor = NULL;
       
   471     delete iCenRep;
       
   472     iCenRep = NULL;
       
   473     }
       
   474 
       
   475     
       
   476 // End of file