locationsystemui/locationsysui/locsysuiview/src/locsettingsuipluginloader.cpp
branchRCL_3
changeset 44 2b4ea9893b66
parent 42 02ba3f1733c6
child 45 6b6920c56e2f
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Manages the E-Comm Plugin handling for the Settings UI.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System Include
       
    20 #include <ecom/implementationinformation.h>
       
    21 #include <aknViewAppUi.h>
       
    22 	
       
    23 // User Include
       
    24 #include "locsettingsuipluginloader.h"
       
    25 #include "locationsettings.h"
       
    26 #include "locsettingsui.h"
       
    27 #include "locsettingsuiparams.h"
       
    28 #include "locsettingsuiecomnotifier.h"
       
    29 
       
    30 
       
    31 // Global Constants
       
    32 
       
    33 //Forward declaration. Function for sorted ordering of settings ui plug-ins
       
    34 static TInt SettingsDescOrdering( const CLocationSettings& aSettings1, 
       
    35 		  					   	  const CLocationSettings& aSettings2 );
       
    36 		  					   	  
       
    37 // ========================= MEMBER FUNCTIONS ================================
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CLocSettingsUiPluginLoader::CLocSettingsUiPluginLoader
       
    41 // Overloaded Constructor
       
    42 //
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CLocSettingsUiPluginLoader::CLocSettingsUiPluginLoader( CAknViewAppUi&	aAppUi )
       
    46 	:CActive( EPriorityStandard ),
       
    47 	iAppUi( aAppUi )
       
    48 	{
       
    49 	// Add self to the Active scheduler
       
    50 	CActiveScheduler::Add( this );			
       
    51 	}
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CLocSettingsUiPluginLoader::~CLocSettingsUiPluginLoader
       
    55 // Destructor
       
    56 //
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CLocSettingsUiPluginLoader::~CLocSettingsUiPluginLoader()
       
    60 	{
       
    61 	Cancel();
       
    62 	}	
       
    63 					 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CLocSettingsUiPluginLoader* CLocSettingsUiPluginLoader::NewL
       
    66 // Creates an instance of the Settings UI Plug-in Loader
       
    67 //
       
    68 // @param  aAppUi				    	App Ui Reference
       
    69 // @return CLocSettingsUiPluginLoader*	Reference to the instantiated class 
       
    70 // ---------------------------------------------------------------------------  
       
    71 //
       
    72 CLocSettingsUiPluginLoader* CLocSettingsUiPluginLoader::NewL( 
       
    73                                                 CAknViewAppUi&	aAppUi )
       
    74 	{
       
    75     CLocSettingsUiPluginLoader* self = 
       
    76                 CLocSettingsUiPluginLoader::NewLC( aAppUi );
       
    77 	CleanupStack::Pop(self);
       
    78 	return self;
       
    79 	}
       
    80 	
       
    81 // ---------------------------------------------------------------------------
       
    82 // CLocSettingsUiPluginLoader* CLocSettingsUiPluginLoader::NewLC
       
    83 // Creates an instance of the Settings UI Plug-in Loader
       
    84 //
       
    85 // @param  aObserver				Observer to the CLocSettingsUiPluginLoader class
       
    86 // @param  aAppUi					App Ui Reference
       
    87 // @return CLocSettingsUiPluginLoader*	Reference to the instantiated class 
       
    88 // ---------------------------------------------------------------------------  
       
    89 //
       
    90 CLocSettingsUiPluginLoader* CLocSettingsUiPluginLoader::NewLC( 
       
    91 								                CAknViewAppUi&	aAppUi )
       
    92 	{
       
    93     CLocSettingsUiPluginLoader* self = new(ELeave) CLocSettingsUiPluginLoader( aAppUi );
       
    94 	CleanupStack::PushL(self);
       
    95 	return self;
       
    96 	}
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // void CLocSettingsUiPluginLoader::CreateAvailableSettingsUisL  
       
   100 // Creates all the settings UI currently available in the system. The 
       
   101 // user if this interface should ensure that he passes an empty
       
   102 // Settings Array structure.
       
   103 // 
       
   104 // @param aDescArray 		 Array of Settings UI.
       
   105 // --------------------------------------------------------------------------- 
       
   106 //
       
   107 void CLocSettingsUiPluginLoader::CreateAvailableSettingsUisL( 
       
   108                                 RPointerArray<CLocationSettings>&   aSettingsArray )
       
   109 	{
       
   110 	// List all the available implementations for KSettingsUiInterfaceUID
       
   111 	RImplInfoPtrArray	impInfoArray;
       
   112 	
       
   113 	REComSession::ListImplementationsL( KSettingsUiInterfaceUID,
       
   114 										impInfoArray );
       
   115 	for ( TInt impInfoArrayIterator = 0; 
       
   116 		 	   impInfoArrayIterator < impInfoArray.Count();
       
   117 		 	   impInfoArrayIterator ++ )
       
   118 		{
       
   119 		// Obtain the Implementation UID
       
   120 		CImplementationInformation* info = impInfoArray[impInfoArrayIterator];
       
   121         TUid implUid = info->ImplementationUid();
       
   122         
       
   123         // Create the Location Settings UI class which inturn creates the
       
   124         // sub-settings plug-in
       
   125              			
       
   126         CLocationSettings* settings = NULL;
       
   127         TRAPD( error, settings = CLocationSettings::NewL( implUid, iAppUi ););
       
   128         if( !error )
       
   129             {
       
   130             // Insert them in order. The order is specified by the SettingsDescOrdering
       
   131     		// function			
       
   132     		error = aSettingsArray.InsertInOrder( settings,
       
   133     											  SettingsDescOrdering );
       
   134     		if ( error )
       
   135     			{
       
   136     			// Issue with creating the Settings UI component. Delete it
       
   137     			delete settings;   			
       
   138     			}
       
   139             }
       
   140 		}
       
   141     // Destroy the implementation info array obtained from ECom Session
       
   142 	impInfoArray.ResetAndDestroy();	
       
   143 	}
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // void CLocSettingsUiPluginLoader::CreateSettingsUiL
       
   147 // Creates the Settings UI and the corresponding description entry. This
       
   148 // Location Settings object. The created object is appended to the existing
       
   149 // list and a reference to it returned.
       
   150 // 
       
   151 // @param aImplementationUid The Implementation UID of the plug-in that
       
   152 //                           has to be created
       
   153 // @param aSettingsArray	 Array of Settings UIs
       
   154 // @return CLocationSettings& Reference to the created object. The ownership is not
       
   155 //                            by the return value.
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 CLocationSettings& CLocSettingsUiPluginLoader::CreateSettingsUiL( 
       
   159                     TUid                                 aImplementationUid,
       
   160                     RPointerArray<CLocationSettings>&    aSettingsArray )
       
   161     {
       
   162     // Create the plug in
       
   163     
       
   164 	// The Function does not check for the existence of the plug-in
       
   165 	// in the implementation array.
       
   166 	
       
   167     // The function is not trapped. If there is a leave then the function would
       
   168     // leave with the error code generated. The calling function has to take 
       
   169     // care of the non-existence of the plug-in
       
   170 	
       
   171 	CLocationSettings* settings = CLocationSettings::NewLC( aImplementationUid,
       
   172 	                                                        iAppUi );
       
   173     			                                                    
       
   174 	// Insert them in order. The order is specified by the SettingsDescOrdering
       
   175 	// function			
       
   176 	User::LeaveIfError(  aSettingsArray.InsertInOrder( settings,
       
   177 											           SettingsDescOrdering ));
       
   178 	CleanupStack::Pop( settings );
       
   179 		
       
   180     // Return the reference to the Settings UI
       
   181     return *settings;			
       
   182     }
       
   183 						        
       
   184 // ---------------------------------------------------------------------------
       
   185 // void CLocSettingsUiPluginLoader::UpdateAvailableSettingsUisL
       
   186 // Updates the Settings UI list and the description structures. The new
       
   187 // additions are appened in-order. The interface does not
       
   188 // delete any instances if they are not in the current implementation 
       
   189 // list
       
   190 // 
       
   191 // @param aSettingsArray     Array of Settings UIs.
       
   192 // @param aInitParams		 Opaque Initialization parameters that are 
       
   193 // 							 passed onto the Settings UI. The PluginLoader 
       
   194 // 							 does not understand these parameters
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 void CLocSettingsUiPluginLoader::UpdateAvailableSettingsUisL( 
       
   198 						RPointerArray<CLocationSettings>&    aSettingsArray )
       
   199 	{
       
   200 		// List all the available implementations for KSettingsUiInterfaceUID
       
   201 	RImplInfoPtrArray	impInfoArray;
       
   202 	
       
   203 	REComSession::ListImplementationsL( KSettingsUiInterfaceUID,
       
   204 										impInfoArray );
       
   205 
       
   206 	for ( TInt impInfoArrayIterator = 0; 
       
   207 		 	   impInfoArrayIterator < impInfoArray.Count();
       
   208 		 	   impInfoArrayIterator ++ )
       
   209 		{
       
   210 		// Obtain the Implementation UID
       
   211 		CImplementationInformation* info = impInfoArray[impInfoArrayIterator];
       
   212         TUid implUid = info->ImplementationUid();
       
   213         
       
   214         // Search if the plug-in already exists.
       
   215         TInt index = KErrNotFound;
       
   216         // Iterate through the Settings UI array
       
   217 		for ( TInt count = 0; count < aSettingsArray.Count(); count++ )
       
   218 		{
       
   219 		CLocationSettings* currentItem = aSettingsArray[count];
       
   220 		// If the Settings object for the Implementation UID already
       
   221 		// exisits then dont do anything
       
   222 		if ( implUid == currentItem->ImplementationUid())
       
   223 			{
       
   224 			index = count;
       
   225 			break;
       
   226 			}
       
   227 		}
       
   228         
       
   229         // If the index value is not set Create the plug in
       
   230         if ( KErrNotFound == index )
       
   231         	{
       
   232             // Create the Location Settings UI class which inturn creates the
       
   233             // sub-settings plug-in
       
   234              			
       
   235             CLocationSettings* settings = NULL;
       
   236             TRAPD( error, settings = CLocationSettings::NewL( implUid, iAppUi ););
       
   237             if( !error )
       
   238                 {
       
   239                 // Insert them in order. The order is specified by the SettingsDescOrdering
       
   240     		    // function			
       
   241     	        error = aSettingsArray.InsertInOrder( settings,
       
   242     												  SettingsDescOrdering );
       
   243     		    if ( error )
       
   244     			    {
       
   245     			    // Issue with creating the Settings UI component. Delete it
       
   246     			    delete settings;   			
       
   247     			    }
       
   248                 }	
       
   249         	}
       
   250 		}
       
   251 	
       
   252 	impInfoArray.ResetAndDestroy();	
       
   253 	}
       
   254 
       
   255 // --------------------------------------------------------------------------- 
       
   256 // Inherited from CActive 
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CLocSettingsUiPluginLoader::RunL()
       
   260 	{
       
   261 	if ( iStatus.Int() != KErrCancel )
       
   262 		{
       
   263 		// Restart the Notification request inorder to listen for future 
       
   264 		// notifications
       
   265 		StartEComNotifyL();
       
   266 		// Notify the state change to the observer
       
   267 		if( iNotifier )
       
   268 		    {
       
   269 		    iNotifier->EComSessionStateChanged( iStatus.Int());
       
   270 		    }		
       
   271 		}
       
   272 	}
       
   273 
       
   274 // --------------------------------------------------------------------------- 
       
   275 // Inherited from CActive 
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CLocSettingsUiPluginLoader::DoCancel()
       
   279 	{
       
   280 	if ( iSession )
       
   281 		{
       
   282 		iSession->CancelNotifyOnChange( iStatus );
       
   283 		iSession->Close();
       
   284 		iSession = NULL;
       
   285 		}		
       
   286 	}
       
   287 
       
   288 // --------------------------------------------------------------------------- 
       
   289 // Inherited from CActive 
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 TInt CLocSettingsUiPluginLoader::RunError( TInt /* aError */)
       
   293 	{
       
   294 	return KErrNone;
       
   295 	}
       
   296 
       
   297 // --------------------------------------------------------------------------- 
       
   298 // Initiates a notify request on the ECom Session
       
   299 //
       
   300 // @param aSettingsNotifer  Notifier for communication of changes in the 
       
   301 //                          Ecom loading and unloading for sub-settings
       
   302 //                          plug-ins 
       
   303 // ---------------------------------------------------------------------------
       
   304 //
       
   305 void CLocSettingsUiPluginLoader::StartEComNotifyL( 
       
   306                     MLocSettingsUiEcomNotifer*   aNotifier )
       
   307 	{
       
   308 	// Set the notifier if its valid
       
   309 	if( aNotifier )
       
   310 	    {
       
   311 	    iNotifier = aNotifier;
       
   312 	    }
       
   313 	
       
   314 	// If the notifier is present then initaite a request    
       
   315     // Open the ECom Session handle if its not been opened
       
   316     if( !iSession )
       
   317         {
       
   318         iSession = &( REComSession::OpenL());
       
   319         }
       
   320 	
       
   321 	// Issue a new request	
       
   322 	if ( !IsActive())
       
   323 		{
       
   324 		// Set the notifier 
       
   325 		iSession->NotifyOnChange( iStatus );	
       
   326 		
       
   327 		SetActive();
       
   328 		}
       
   329 	}
       
   330         
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 // Stop the outstanding EComNotification
       
   334 // ---------------------------------------------------------------------------
       
   335 //
       
   336 void CLocSettingsUiPluginLoader::StopEComNotify()
       
   337     {
       
   338     // Cancel any outstanding request
       
   339     Cancel();
       
   340     }
       
   341         	
       
   342 // ---------------------------------------------------------------------------
       
   343 // static TInt SettingsDescOrdering
       
   344 // Ordering function for inserting the elements into the List box array.
       
   345 // The ordering is done first based on the priority. 
       
   346 //
       
   347 // @param CLocationSettings& First Settings Element
       
   348 // @param CLocationSettings& Second Settings Element
       
   349 // @return 1. zero, if the two objects are equal.
       
   350 //
       
   351 //		   2. a negative value, if the first object is less than the second.
       
   352 //
       
   353 // 		   3. a positive value, if the first object is greater than the second.
       
   354 // 
       
   355 // ---------------------------------------------------------------------------	
       
   356 TInt SettingsDescOrdering( const CLocationSettings& aSettings1, 
       
   357 		  				   const CLocationSettings& aSettings2 )
       
   358     {
       
   359     CLocationSettings* settings1 = const_cast< CLocationSettings*>(&aSettings1);
       
   360     CLocationSettings* settings2 = const_cast< CLocationSettings*>(&aSettings2);
       
   361     return ( settings1->Priority() - settings2->Priority());
       
   362 	}