homescreenpluginsrv/hspsmanager/src/hspsfamilylistener.cpp
branchRCL_3
changeset 14 15e4dd19031c
parent 0 79c6a41cd166
equal deleted inserted replaced
12:502e5d91ad42 14:15e4dd19031c
    17 */
    17 */
    18 
    18 
    19 #include "hspsfamilylistener.h"
    19 #include "hspsfamilylistener.h"
    20 #include "hsps_builds_cfg.hrh"
    20 #include "hsps_builds_cfg.hrh"
    21 #include "hspsmanifest.h"
    21 #include "hspsmanifest.h"
    22 #include <featmgr.h>
       
    23 
    22 
    24 
    23 
    25 _LIT8(KTch, "_tch");
    24 _LIT8(KTch, "_tch");
    26 const TInt KMaxFamilyLength( 20 );
    25 const TInt KMaxFamilyLength( 20 );
    27 
    26 
    33 // ChspsFamilyListener::NewL
    32 // ChspsFamilyListener::NewL
    34 // -----------------------------------------------------------------------------
    33 // -----------------------------------------------------------------------------
    35 //
    34 //
    36 ChspsFamilyListener* ChspsFamilyListener::NewL( MhspsFamilyObserver& aObserver )
    35 ChspsFamilyListener* ChspsFamilyListener::NewL( MhspsFamilyObserver& aObserver )
    37     {
    36     {
    38     ChspsFamilyListener* self = new(ELeave) ChspsFamilyListener( aObserver );
    37     ChspsFamilyListener* self = new(ELeave) ChspsFamilyListener( );
    39     CleanupStack::PushL( self );
    38     CleanupStack::PushL( self );
    40     self->ConstructL();
    39     self->ConstructL( aObserver );
    41     CleanupStack::Pop( self );
    40     CleanupStack::Pop( self );
    42     return self;
    41     return self;
    43     }
    42     }
    44 
    43 
    45 // -----------------------------------------------------------------------------
    44 // -----------------------------------------------------------------------------
    46 // ChspsFamilyListener::ChspsFamilyListener
    45 // ChspsFamilyListener::ChspsFamilyListener
    47 // -----------------------------------------------------------------------------
    46 // -----------------------------------------------------------------------------
    48 //
    47 //
    49 ChspsFamilyListener::ChspsFamilyListener( MhspsFamilyObserver& aObserver ) 
    48 ChspsFamilyListener::ChspsFamilyListener() 
    50     : CActive( EPriorityStandard ), iObserver( aObserver), iActiveFamily( EhspsFamilyUnknown )    
       
    51     {
    49     {
    52     CActiveScheduler::Add(this);
       
    53     }
    50     }
    54 
    51 
    55 // -----------------------------------------------------------------------------
    52 // -----------------------------------------------------------------------------
    56 // ChspsFamilyListener::ConstructL
    53 // ChspsFamilyListener::ConstructL
    57 // -----------------------------------------------------------------------------
    54 // -----------------------------------------------------------------------------
    58 //
    55 //
    59 void ChspsFamilyListener::ConstructL()
    56 void ChspsFamilyListener::ConstructL( MhspsFamilyObserver& aObserver )
    60     {    
    57     {    
    61     User::LeaveIfError( iWsSession.Connect() );
    58 
    62     
    59     // ChspsFamily::ConstructL ChspsFamily's second phase constructor call 
       
    60     ChspsFamily::ConstructL();
       
    61 
       
    62     iFamilyListenerActive = ChspsFamilyListenerActive::NewL( *this, aObserver );
       
    63 
    63     // A group needs to be instansiated so that we're able to receive events 
    64     // A group needs to be instansiated so that we're able to receive events 
    64     iWindowGroup = RWindowGroup( iWsSession );
    65     iWindowGroup = RWindowGroup( WsSession() );
    65     User::LeaveIfError( iWindowGroup.Construct(2,ETrue) ); // '2' is a meaningless handle
    66     User::LeaveIfError( iWindowGroup.Construct(2,ETrue) ); // '2' is a meaningless handle
    66     
    67     
    67     // Enables for EEventScreenDeviceChanged events
    68     // Enables for EEventScreenDeviceChanged events
    68     iWindowGroup.EnableScreenChangeEvents(); 
    69     iWindowGroup.EnableScreenChangeEvents(); 
    69             
       
    70     iScreenDevice = new (ELeave) CWsScreenDevice( iWsSession );
       
    71     User::LeaveIfError( iScreenDevice->Construct() );  
       
    72     
    70     
    73     // Start the listener
    71     // Start the listener
    74     Queue();    
    72     iFamilyListenerActive->Queue();    
    75     }
    73     }
    76 
    74 
       
    75 
       
    76 
       
    77 
       
    78 
       
    79 ChspsFamilyListenerActive* ChspsFamilyListenerActive::NewL( 
       
    80     ChspsFamilyListener& aListener,
       
    81     MhspsFamilyObserver& aObserver )
       
    82     {
       
    83     ChspsFamilyListenerActive* self = new( ELeave ) ChspsFamilyListenerActive( 
       
    84             aListener,
       
    85             aObserver );
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     CleanupStack::Pop( self );
       
    89     return self;
       
    90     }
       
    91         
       
    92 ChspsFamilyListenerActive::~ChspsFamilyListenerActive()
       
    93 	{
       
    94     Cancel();
       
    95 	}
       
    96 
       
    97 void ChspsFamilyListenerActive::ConstructL()
       
    98 	{
       
    99 	}
       
   100 
       
   101 ChspsFamilyListenerActive::ChspsFamilyListenerActive( 
       
   102 		ChspsFamilyListener& aListener,
       
   103 		MhspsFamilyObserver& aObserver )
       
   104     :CActive( EPriorityStandard ), 
       
   105     iListener( aListener),
       
   106     iObserver( aObserver )
       
   107 	{
       
   108     CActiveScheduler::Add(this);
       
   109 	}
       
   110 
       
   111 
    77 // ------------------------------------------------------------------------------
   112 // ------------------------------------------------------------------------------
    78 // ChspsFamilyListener::Queue
   113 // ChspsFamilyListenerActive::Queue
    79 // ------------------------------------------------------------------------------
   114 // ------------------------------------------------------------------------------
    80 void ChspsFamilyListener::Queue()
   115 void ChspsFamilyListenerActive::Queue()
    81     {
   116     {
    82     ASSERT ( !IsActive() );
   117     ASSERT ( !IsActive() );
    83     iWsSession.EventReady( &iStatus );
   118     iListener.WsSession().EventReady( &iStatus );
    84     SetActive();
   119     SetActive();
    85     }
   120     }
    86 
   121 
    87 // ------------------------------------------------------------------------------
   122 // ------------------------------------------------------------------------------
    88 // ChspsFamilyListener::~ChspsFamilyListener
   123 // ChspsFamilyListener::~ChspsFamilyListener
    89 // ------------------------------------------------------------------------------
   124 // ------------------------------------------------------------------------------
    90 ChspsFamilyListener::~ChspsFamilyListener()
   125 ChspsFamilyListener::~ChspsFamilyListener()
    91     {
   126     {
    92     Cancel();
   127     if ( iFamilyListenerActive )
    93     if ( iFeatureManagerLoaded )
       
    94         {
   128         {
    95         FeatureManager::UnInitializeLib();
   129         delete iFamilyListenerActive;
    96         }
   130         }
    97     delete iScreenDevice;
       
    98     iWindowGroup.Close();
   131     iWindowGroup.Close();
    99     iWsSession.Close();    
       
   100     }
   132     }
   101 
   133 
   102 // -----------------------------------------------------------------------------
   134 
   103 // ChspsFileChangeListener::GetFamilyString 
   135 
   104 // -----------------------------------------------------------------------------
       
   105 void ChspsFamilyListener::GetFamilyString(        
       
   106         TDes8& aFamily )
       
   107     {                     
       
   108     // Append input with a prefix based on the active screen resolution    
       
   109     TPixelsTwipsAndRotation sizeAndRotation;
       
   110     iScreenDevice->GetDefaultScreenSizeAndRotation( sizeAndRotation );
       
   111     TSize resolution( sizeAndRotation.iPixelSize );  
       
   112     if( resolution.iWidth > resolution.iHeight )
       
   113         {
       
   114         TInt temp = resolution.iHeight;
       
   115         resolution.iHeight = resolution.iWidth;
       
   116         resolution.iWidth = temp;        
       
   117         }          
       
   118     switch( resolution.iHeight )
       
   119         {
       
   120         case 320:
       
   121             {
       
   122             if ( resolution.iWidth == 240 )
       
   123                 {
       
   124                 aFamily.Append( KFamilyQvga );
       
   125                 }
       
   126             }
       
   127             break;
       
   128         case 640:
       
   129             {
       
   130             if( resolution.iWidth == 360 )
       
   131                 {
       
   132                 aFamily.Append( KFamilyQhd );
       
   133                 }
       
   134             else if( resolution.iWidth == 480 )
       
   135                 {
       
   136                 aFamily.Append( KFamilyVga );
       
   137                 }            
       
   138             }
       
   139             break;
       
   140         
       
   141         default:
       
   142             break;
       
   143         }    
       
   144     if( aFamily.Length() > 0 )
       
   145         {                     
       
   146 //        // Append input with a suffix based on the touch support
       
   147 //        if ( !iFeatureManagerLoaded )
       
   148 //            {
       
   149 //            FeatureManager::InitializeLibL();
       
   150 //            iFeatureManagerLoaded = ETrue;
       
   151 //            }
       
   152 //        if ( FeatureManager::FeatureSupported( KFeatureIdPenSupport ) )
       
   153 //            {
       
   154             aFamily.Append( KTch );
       
   155 //            }                
       
   156         }
       
   157     }
       
   158 
   136 
   159 // -----------------------------------------------------------------------------
   137 // -----------------------------------------------------------------------------
   160 // ChspsFileChangeListener::GetFamilyType 
   138 // ChspsFamilyListener::RunL 
   161 // -----------------------------------------------------------------------------
   139 // -----------------------------------------------------------------------------
   162 ThspsFamily ChspsFamilyListener::GetFamilyType( 
   140 void ChspsFamilyListenerActive::RunL()
   163         const TDesC8& aFamilyString )
       
   164     {
       
   165     ThspsFamily family( EhspsFamilyUnknown );
       
   166     
       
   167     if( aFamilyString == KFamilyQvga )
       
   168        {
       
   169        family = EhspsFamilyQvga;
       
   170        }
       
   171     else if( aFamilyString == KFamilyQvga2 )
       
   172        {
       
   173        family = EhspsFamilyQvga2;
       
   174        }
       
   175     else if( aFamilyString == KFamilyVga )
       
   176        {
       
   177        family = EhspsFamilyVga;            
       
   178        }
       
   179     else if( aFamilyString == KFamilyVga3 )
       
   180        {
       
   181        family = EhspsFamilyVga3;
       
   182        }
       
   183     else if( aFamilyString == KFamilyQhd )
       
   184        {
       
   185        family = EhspsFamilyQhd;
       
   186        }
       
   187     else if( aFamilyString == KFamilyQhd_tch )
       
   188        {
       
   189        family = EhspsFamilyQhd_tch;
       
   190        }
       
   191    else if( aFamilyString == KFamilyVga_tch )
       
   192        {
       
   193        family = EhspsFamilyVga_tch;
       
   194        }    
       
   195    
       
   196     return family;     
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // ChspsFileChangeListener::GetFamilyType
       
   201 // -----------------------------------------------------------------------------
       
   202 ThspsFamily ChspsFamilyListener::GetFamilyType()
       
   203     {
       
   204     TBuf8<KMaxFamilyLength> familyString;
       
   205     GetFamilyString( familyString );   
       
   206     return GetFamilyType( familyString );
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // ChspsFileChangeListener::RunL 
       
   211 // -----------------------------------------------------------------------------
       
   212 void ChspsFamilyListener::RunL()
       
   213     {
   141     {
   214     TWsEvent wsEvent;
   142     TWsEvent wsEvent;
   215     iWsSession.GetEvent(wsEvent);                                   
   143     iListener.WsSession().GetEvent(wsEvent);
   216     switch( wsEvent.Type() )
   144     switch( wsEvent.Type() )
   217         {
   145         {
   218         case EEventScreenDeviceChanged:
   146         case EEventScreenDeviceChanged:
   219             {                    
   147             {                    
   220             ThspsFamily newFamily = GetFamilyType();
   148             ThspsFamily newFamily = iListener.GetFamilyType();
   221             if ( newFamily > EhspsFamilyUnknown )
   149             if ( newFamily > EhspsFamilyUnknown )
   222                 {                
   150                 {                
   223                 iObserver.HandleFamilyChangeL( newFamily );
   151                 iObserver.HandleFamilyChangeL( newFamily );
   224                 iActiveFamily = newFamily;
       
   225                 }
   152                 }
   226             break;
   153             break;
   227             }
   154             }
   228         default:
   155         default:
   229             break;
   156             break;
   234  
   161  
   235 // -----------------------------------------------------------------------------
   162 // -----------------------------------------------------------------------------
   236 // ChspsFileChangeListener::DoCancel
   163 // ChspsFileChangeListener::DoCancel
   237 // -----------------------------------------------------------------------------
   164 // -----------------------------------------------------------------------------
   238 //
   165 //
   239 void ChspsFamilyListener::DoCancel()
   166 void ChspsFamilyListenerActive::DoCancel()
   240     {
   167     {
   241     iWsSession.EventReadyCancel();
   168     iListener.WsSession().EventReadyCancel();
   242     }
   169     }
   243  
   170  
   244 // -----------------------------------------------------------------------------
   171 // -----------------------------------------------------------------------------
   245 // ChspsFileChangeListener::RunError
   172 // ChspsFileChangeListener::RunError
   246 // -----------------------------------------------------------------------------
   173 // -----------------------------------------------------------------------------
   247 TInt ChspsFamilyListener::RunError(TInt /*aError*/)
   174 TInt ChspsFamilyListenerActive::RunError(TInt /*aError*/)
   248     {
   175     {
   249     return KErrNone;
   176     return KErrNone;
   250     }
   177     }
   251 
   178 
   252 // End of File
   179 // End of File