homescreenpluginsrv/hspsmanager/src/hspsfamilylistener.cpp
changeset 0 79c6a41cd166
child 14 15e4dd19031c
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  FamilyListener listens to resolution&orientation
       
    15 *               changes in emulator environment.
       
    16 *
       
    17 */
       
    18 
       
    19 #include "hspsfamilylistener.h"
       
    20 #include "hsps_builds_cfg.hrh"
       
    21 #include "hspsmanifest.h"
       
    22 #include <featmgr.h>
       
    23 
       
    24 
       
    25 _LIT8(KTch, "_tch");
       
    26 const TInt KMaxFamilyLength( 20 );
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // ChspsFamilyListener::NewL
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 ChspsFamilyListener* ChspsFamilyListener::NewL( MhspsFamilyObserver& aObserver )
       
    37     {
       
    38     ChspsFamilyListener* self = new(ELeave) ChspsFamilyListener( aObserver );
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // ChspsFamilyListener::ChspsFamilyListener
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 ChspsFamilyListener::ChspsFamilyListener( MhspsFamilyObserver& aObserver ) 
       
    50     : CActive( EPriorityStandard ), iObserver( aObserver), iActiveFamily( EhspsFamilyUnknown )    
       
    51     {
       
    52     CActiveScheduler::Add(this);
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // ChspsFamilyListener::ConstructL
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void ChspsFamilyListener::ConstructL()
       
    60     {    
       
    61     User::LeaveIfError( iWsSession.Connect() );
       
    62     
       
    63     // A group needs to be instansiated so that we're able to receive events 
       
    64     iWindowGroup = RWindowGroup( iWsSession );
       
    65     User::LeaveIfError( iWindowGroup.Construct(2,ETrue) ); // '2' is a meaningless handle
       
    66     
       
    67     // Enables for EEventScreenDeviceChanged events
       
    68     iWindowGroup.EnableScreenChangeEvents(); 
       
    69             
       
    70     iScreenDevice = new (ELeave) CWsScreenDevice( iWsSession );
       
    71     User::LeaveIfError( iScreenDevice->Construct() );  
       
    72     
       
    73     // Start the listener
       
    74     Queue();    
       
    75     }
       
    76 
       
    77 // ------------------------------------------------------------------------------
       
    78 // ChspsFamilyListener::Queue
       
    79 // ------------------------------------------------------------------------------
       
    80 void ChspsFamilyListener::Queue()
       
    81     {
       
    82     ASSERT ( !IsActive() );
       
    83     iWsSession.EventReady( &iStatus );
       
    84     SetActive();
       
    85     }
       
    86 
       
    87 // ------------------------------------------------------------------------------
       
    88 // ChspsFamilyListener::~ChspsFamilyListener
       
    89 // ------------------------------------------------------------------------------
       
    90 ChspsFamilyListener::~ChspsFamilyListener()
       
    91     {
       
    92     Cancel();
       
    93     if ( iFeatureManagerLoaded )
       
    94         {
       
    95         FeatureManager::UnInitializeLib();
       
    96         }
       
    97     delete iScreenDevice;
       
    98     iWindowGroup.Close();
       
    99     iWsSession.Close();    
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // ChspsFileChangeListener::GetFamilyString 
       
   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 
       
   159 // -----------------------------------------------------------------------------
       
   160 // ChspsFileChangeListener::GetFamilyType 
       
   161 // -----------------------------------------------------------------------------
       
   162 ThspsFamily ChspsFamilyListener::GetFamilyType( 
       
   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     {
       
   214     TWsEvent wsEvent;
       
   215     iWsSession.GetEvent(wsEvent);                                   
       
   216     switch( wsEvent.Type() )
       
   217         {
       
   218         case EEventScreenDeviceChanged:
       
   219             {                    
       
   220             ThspsFamily newFamily = GetFamilyType();
       
   221             if ( newFamily > EhspsFamilyUnknown )
       
   222                 {                
       
   223                 iObserver.HandleFamilyChangeL( newFamily );
       
   224                 iActiveFamily = newFamily;
       
   225                 }
       
   226             break;
       
   227             }
       
   228         default:
       
   229             break;
       
   230     }
       
   231        
       
   232     Queue();    
       
   233     }
       
   234  
       
   235 // -----------------------------------------------------------------------------
       
   236 // ChspsFileChangeListener::DoCancel
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void ChspsFamilyListener::DoCancel()
       
   240     {
       
   241     iWsSession.EventReadyCancel();
       
   242     }
       
   243  
       
   244 // -----------------------------------------------------------------------------
       
   245 // ChspsFileChangeListener::RunError
       
   246 // -----------------------------------------------------------------------------
       
   247 TInt ChspsFamilyListener::RunError(TInt /*aError*/)
       
   248     {
       
   249     return KErrNone;
       
   250     }
       
   251 
       
   252 // End of File
       
   253