locationcentre/lcapp/src/lcappui.cpp
changeset 0 522cd55cc3d7
equal deleted inserted replaced
-1:000000000000 0:522cd55cc3d7
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Application class for Location Centre Application UI.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM FILES
       
    20 #include <avkon.hrh>
       
    21 #include <lcservice.h>
       
    22 #include <lclocationappinfo.h>
       
    23 #include <lclocationappfilter.h>
       
    24 #include <AknsConstants.h>
       
    25 #include <aknnotewrappers.h>
       
    26 #include <textresolver.h>
       
    27 
       
    28 // USER INCLUDES
       
    29 #include "lcappui.h"
       
    30 #include "lcapp.hrh"
       
    31 #include "lcview.h"
       
    32 #include "lclistboxmodel.h"
       
    33 
       
    34 // ----------------- Member funtions for CLcApp ------------------------------
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // void CLcAppUi::ConstructL
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 void CLcAppUi::ConstructL()
       
    41     {
       
    42     BaseConstructL( EAknEnableSkin | EAknEnableMSK |EAknSingleClickCompatible );
       
    43     
       
    44     // Create the Service class
       
    45     iLcService = CLcService::NewL();    
       
    46     iLcService->SetObserverL( *this );
       
    47     
       
    48     // Handle condition where the function leaves with KErrNotFound
       
    49     // Create the Listbox Model
       
    50     
       
    51     CLcLocationAppInfoArray* appInfoArray = NULL;
       
    52     TRAPD( error, appInfoArray = iLcService->GetLocationApplicationsL());
       
    53     if ( KErrNotFound == error || KErrNone == error )
       
    54     	{
       
    55     	CleanupStack::PushL( appInfoArray );
       
    56     	// The ownership of the array is transferred.
       
    57     	iListBoxModel = CLcListBoxModel::NewL( appInfoArray );    	
       
    58     	CleanupStack::Pop( appInfoArray );
       
    59     	}
       
    60 	else
       
    61 		{
       
    62 		// Not handling other error conditions. So better let others handle it.
       
    63 		User::Leave( error );
       
    64 		}
       
    65     
       
    66     // Create the View object and add it to the View stack
       
    67     CLcView* lcView = CLcView::NewL( *this, *iListBoxModel );
       
    68     CleanupStack::PushL( lcView );  	
       
    69     AddViewL( lcView );
       
    70     CleanupStack::Pop( lcView );
       
    71     iLcView = lcView;
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CLcAppUi::~CLcAppUi
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CLcAppUi::~CLcAppUi()
       
    79     {        
       
    80     // Delete the Service class    
       
    81     delete iLcService;
       
    82     
       
    83     // Delete the Model
       
    84     delete iListBoxModel;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // TKeyResponse CLcAppUi::HandleKeyEventL
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 TKeyResponse CLcAppUi::HandleKeyEventL( const TKeyEvent& /*aKeyEvent*/,
       
    92                                               TEventCode /*aType*/ )
       
    93     {
       
    94     return EKeyWasNotConsumed;
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // void CLcAppUi::HandleCommandL
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CLcAppUi::HandleCommandL( TInt aCommand )
       
   102     {
       
   103     switch ( aCommand )
       
   104         {
       
   105         case EAknSoftkeyExit: 
       
   106         case EEikCmdExit:
       
   107             {
       
   108             Exit();
       
   109             break;
       
   110             }
       
   111         case ELcOpen:
       
   112             {
       
   113             HandleEventL( ELcOpen );
       
   114             break;
       
   115             }
       
   116        default: 
       
   117        	    { 	          	           	    
       
   118        	    break; 
       
   119        	    }
       
   120         }
       
   121     }
       
   122 	
       
   123 // ---------------------------------------------------------------------------
       
   124 // void CLcAppUi::LcStatusChangedL
       
   125 // ---------------------------------------------------------------------------
       
   126 //    
       
   127 void CLcAppUi::LcStatusChangedL( TInt aErrorCode )
       
   128     {
       
   129     // Update the listbox only if its a valid update.		
       
   130     if ( KErrNone == aErrorCode )
       
   131     	{
       
   132     	// There has been a change in Location Centre's registry. We have to
       
   133     	// update the list of Applications
       
   134     	
       
   135 	    CLcLocationAppInfoArray* appInfoArray = NULL;
       
   136 	    TRAPD( error, appInfoArray = iLcService->GetLocationApplicationsL());
       
   137 	    if ( KErrNotFound == error || KErrNone == error )
       
   138 	    	{
       
   139 	    	// The ownership of the new array is transferred.
       
   140 	    	iListBoxModel->UpdateModel( appInfoArray );
       
   141 	    	iLcView->UpdateL( *iListBoxModel );   	
       
   142 	    	}
       
   143 		else
       
   144 			{
       
   145 			// Not handling other error conditions. So better let others handle it.
       
   146 			User::Leave( error );
       
   147 			}    	
       
   148     	}
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // void CLcAppUi::HandleEventL
       
   153 // ---------------------------------------------------------------------------
       
   154 //    
       
   155 void CLcAppUi::HandleEventL( TInt	aEvent )
       
   156 	{
       
   157 	switch( aEvent )
       
   158 		{
       
   159 		case KEikDynamicLayoutVariantSwitch:
       
   160 			{
       
   161 			// Request the Client container to change its rect to a new Rect
       
   162 			iLcView->ScreenSizeChanged();
       
   163 			break;
       
   164 			}
       
   165 		case KAknsMessageSkinChange:
       
   166 			{
       
   167 			iLcView->UpdateIconsL();
       
   168 			break;
       
   169 			}
       
   170 		case ELcOpen:
       
   171 			{
       
   172 			// Obtain the Identifier corresponding to the Selected Item
       
   173 			TInt selectedItem = iLcView->GetFocussedItem();
       
   174 			if ( selectedItem >= 0 && selectedItem < iListBoxModel->MdcaCount())
       
   175 				{
       
   176 				TRAP_IGNORE( iLcService->
       
   177 						LaunchLocationApplicationL( iListBoxModel->AppInfoId( selectedItem )));
       
   178 				}
       
   179 			break;
       
   180 			}
       
   181 		default:
       
   182 			break;
       
   183 		}
       
   184 	}
       
   185 	
       
   186 // End of File