phonebookui/Phonebook2/ccapplication/ccapp/src/ccapppluginloader.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 68 9da50d567e3c
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 
       
     2 /*
       
     3 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * Nokia Corporation - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 *
       
    15 * Description:  Class for loading and handling the plugins
       
    16 *
       
    17 */
       
    18 
       
    19 #include <e32def.h>
       
    20 #include <centralrepository.h>
       
    21 
       
    22 #include <mccaparentcleaner.h>
       
    23 #include <mccapluginfactory.h>
       
    24 
       
    25 #include <cpbk2applicationservices.h>
       
    26 #include <CPbk2StoreConfiguration.h>
       
    27 #include <CVPbkContactManager.h>
       
    28 #include <MVPbkContactStoreProperties.h>
       
    29 #include <VPbkContactStoreUris.h>
       
    30 #include <TVPbkContactStoreUriPtr.h>
       
    31 #include <MVPbkContactStore.h>
       
    32 #include "Phonebook2PrivateCRKeys.h"
       
    33 #include "ccappheaders.h"
       
    34 #include "tccapluginsorderinfo.h"
       
    35 #include "ccapluginfactoryowner.h"
       
    36 #include "../../ccadetailsviewplugin/inc/ccappdetailsviewpluginuids.hrh"
       
    37 #include "../../ccacommlauncherplugin/inc/ccappcommlauncherpluginuids.hrh"
       
    38 #include "../inc/ccappmycardpluginuids.hrh"
       
    39 
       
    40 #include <Pbk2DataCaging.hrh>
       
    41 
       
    42 
       
    43 // ======== CONSTANTS ==============
       
    44 const TInt KMaxPlugins = 255;
       
    45 //TODO: put these to common header
       
    46 _LIT8( KCcaOpaqueNameDelimiter,     "\t" ); //Name=value pairs separated by tabs
       
    47 _LIT8( KCcaOpaqueValueDelimiter,    "=" );  //Names and values separated by =
       
    48 _LIT8( KCcaOpaqueTABP,              "TABP" );  //Tab position
       
    49 
       
    50 _LIT(KPbk2CommandsDllResFileName,   "Pbk2Commands.rsc");
       
    51 _LIT(KPbk2UiControlsDllResFileName, "Pbk2UiControls.rsc");
       
    52 _LIT(KPbk2CommonUiDllResFileName,   "Pbk2CommonUi.rsc"  );
       
    53 
       
    54 // ======== LOCAL FUNCTIONS ========
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // OrderOfPlugins (local function)
       
    58 //
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 TInt OrderOfPlugins( const CImplementationInformation& aFirst,
       
    62             const CImplementationInformation& aSecond )
       
    63     {
       
    64     TInt firstVal = KMaxPlugins;
       
    65     TInt secondVal = KMaxPlugins;
       
    66 
       
    67     TLex8 lex( aFirst.OpaqueData() );
       
    68     lex.Val( firstVal );
       
    69 
       
    70     lex = aSecond.OpaqueData();
       
    71     lex.Val( secondVal );
       
    72 
       
    73     if( firstVal < secondVal )
       
    74         {
       
    75         return -1;
       
    76         }
       
    77     else if( firstVal == secondVal )
       
    78         {
       
    79         return 0;
       
    80         }
       
    81     else
       
    82         {
       
    83         return 1;
       
    84         }
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CleanupResetAndDestroy (local function)
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CleanupResetAndDestroy(TAny* aObj)
       
    92     {
       
    93     if (aObj)
       
    94         {
       
    95         static_cast<RImplInfoPtrArray*>(aObj)->ResetAndDestroy();
       
    96         }
       
    97     }
       
    98 
       
    99 // ======== MEMBER FUNCTIONS ========
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CCCAppPluginLoader::CCCAppPluginLoader
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 CCCAppPluginLoader::CCCAppPluginLoader(MCCAppEngine* aAppEngine) : 
       
   106 	iAppEngine(aAppEngine),
       
   107     iCommandsResourceFile( *CCoeEnv::Static() ),
       
   108     iUiControlsResourceFile( *CCoeEnv::Static() ),
       
   109     iCommonUiResourceFile( *CCoeEnv::Static() )
       
   110     {
       
   111     CCA_DP( KCCAppLogFile, CCA_L("CCCAppPluginData::CCCAppPluginLoader"));
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CCCAppPluginLoader::~CCCAppPluginLoader
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 CCCAppPluginLoader::~CCCAppPluginLoader()
       
   119     {
       
   120     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::~CCCAppPluginLoader"));
       
   121 
       
   122     //Nullify pointer to AppEngine in plugins as otherwise it will point to object
       
   123     //that doesn't exist anymore at this point of execution (because views are
       
   124     //deleted after AppEngine).
       
   125     for(TInt i = 0; i < PluginsCount(); i++)
       
   126         {
       
   127         CCCAppViewPluginBase& plugin(iPluginDataArray[i]->Plugin());
       
   128         plugin.SetAppEngine(NULL);
       
   129         }
       
   130 
       
   131     iPluginDataArray.ResetAndDestroy();
       
   132     delete iFactoryTempPtr;
       
   133     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::~CCCAppPluginLoader"));
       
   134     
       
   135     if(iAppServices)
       
   136         {
       
   137         iAppServices->StoreConfiguration().RemoveObserver(*this);
       
   138         }
       
   139     Release( iAppServices );
       
   140 
       
   141     iCommandsResourceFile.Close();
       
   142     iUiControlsResourceFile.Close();
       
   143     iCommonUiResourceFile.Close();
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CCCAppPluginLoader::NewL
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 CCCAppPluginLoader* CCCAppPluginLoader::NewL(
       
   151     MCCAppEngine* aAppEngine,
       
   152     const TDesC8& aPluginProperties,
       
   153     const TDesC8& aTypeFilter )
       
   154     {
       
   155     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::NewL"));
       
   156 
       
   157     CCCAppPluginLoader* self = new( ELeave ) CCCAppPluginLoader(aAppEngine);
       
   158     CleanupStack::PushL( self );
       
   159     self->ConstructL(aPluginProperties, aTypeFilter );
       
   160     CleanupStack::Pop( self );
       
   161 
       
   162     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::NewL"));
       
   163     return self;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CCCAppPluginLoader::ConstructL
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CCCAppPluginLoader::ConstructL(
       
   171     const TDesC8& aPluginProperties,
       
   172     const TDesC8& aTypeFilter )
       
   173     {
       
   174     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::ConstructL"));
       
   175 
       
   176     //PERFORMANCE LOGGING: 3. Loading plugins
       
   177     WriteToPerfLog();
       
   178 
       
   179     PreparePbk2ApplicationServicesL();
       
   180     
       
   181     RPointerArray<CImplementationInformation> oldImplInfoArray;
       
   182     CleanupStack::PushL(TCleanupItem(CleanupResetAndDestroy, &oldImplInfoArray));
       
   183     RPointerArray<CImplementationInformation> newImplInfoArray;
       
   184     CleanupStack::PushL(TCleanupItem(CleanupResetAndDestroy, &newImplInfoArray));
       
   185 
       
   186     FeatureManager::InitializeLibL();
       
   187     const TBool myCardSupported( 
       
   188             FeatureManager::FeatureSupported( KFeatureIdffContactsMycard ) );    
       
   189     FeatureManager::UnInitializeLib();
       
   190     
       
   191     // A. List legacy and new implementations
       
   192     if( myCardSupported && 
       
   193             aTypeFilter.Length() > 0 )
       
   194         {
       
   195         TEComResolverParams params;
       
   196         params.SetDataType( aTypeFilter );
       
   197 
       
   198         REComSession::ListImplementationsL( 
       
   199                 TUid::Uid(KCCAppViewPluginBaseInterfaceUID),
       
   200             params, oldImplInfoArray );
       
   201         REComSession::ListImplementationsL( KCCAppViewFactoryInterfaceUID,
       
   202             params, newImplInfoArray );
       
   203         }
       
   204     else
       
   205         {
       
   206         REComSession::ListImplementationsL( 
       
   207                 TUid::Uid(KCCAppViewPluginBaseInterfaceUID),
       
   208             oldImplInfoArray );
       
   209         REComSession::ListImplementationsL( KCCAppViewFactoryInterfaceUID,
       
   210             newImplInfoArray );
       
   211         }
       
   212 
       
   213     if ( !myCardSupported && 
       
   214             !oldImplInfoArray.Count() )  //At least one legacy plugin needed
       
   215         {// no plugins, nothing can be done
       
   216         CCA_DP( KCCAppLogFile, CCA_L( "::ConstructL - no plugins found!"));
       
   217         User::Leave( KErrNotFound );
       
   218         }
       
   219 
       
   220     // B. Sort implementations into same order as are in Phonebook
       
   221     // each stores pluginInfo (from oldImplInfoArray) address and order
       
   222     RArray<TCCAPluginsOrderInfo> pluginOrderArray;
       
   223     CleanupClosePushL( pluginOrderArray );
       
   224     RArray<TPtrC> nameArray; // stores phonebooksXPExtension plugins name
       
   225     CleanupClosePushL(nameArray);
       
   226 
       
   227     // store phonebook mainview sXPExtension's name from CenRep to nameArray
       
   228     CRepository* repository = CRepository::NewLC( TUid::Uid(KCRUidPhonebook));
       
   229     HBufC* names = HBufC::NewLC(NCentralRepositoryConstants::KMaxUnicodeStringLength);
       
   230     TPtr namesPtr = names->Des();
       
   231 
       
   232     // get key value, which stores phonebook sXPExtension Plugins name
       
   233     TInt error = repository->Get(KPhonebooksXPExtensionPluginsName, namesPtr);
       
   234 
       
   235     // e.g if the bey value is "MSN|Ovi|Sonera|....",then MSN, Ovi and Sonera
       
   236     // will be appended to aPbksXPExtesionNamesArray
       
   237     GetPbksXPExtesionNamesL(nameArray, *names); //parses names to namearray
       
   238 
       
   239 
       
   240     // copy CImplementationInformation's address from oldImplInfoArray to pluginOrderArray
       
   241     GetPluginsInfoL(pluginOrderArray, nameArray, oldImplInfoArray, newImplInfoArray);
       
   242 
       
   243     SortPluginsOrderInfoL( pluginOrderArray, nameArray );
       
   244 
       
   245     // C. Load implementations in defined order
       
   246     LoadAllPlugins(pluginOrderArray, aPluginProperties);
       
   247 
       
   248     CleanupStack::PopAndDestroy(names);
       
   249     CleanupStack::PopAndDestroy(repository);
       
   250 
       
   251     CleanupStack::PopAndDestroy(); //nameArray
       
   252     CleanupStack::PopAndDestroy(); //pluginOrderArray
       
   253     CleanupStack::PopAndDestroy(&newImplInfoArray);
       
   254     CleanupStack::PopAndDestroy(&oldImplInfoArray);
       
   255     //PERFORMANCE LOGGING: 4. Plugins loaded
       
   256     WriteToPerfLog();
       
   257 
       
   258     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::ConstructL"));
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CCCAppPluginLoader::LoadOneMultiViewPluginL
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 void CCCAppPluginLoader::LoadOneMultiViewPluginL(
       
   266     CImplementationInformation* aImplementationInformation)
       
   267     {
       
   268     __ASSERT_DEBUG(!iFactoryTempPtr, User::Panic(_L("CCCAppPluginLoad"), KErrAlreadyExists));
       
   269     iFactoryTempPtr = CcaPluginFactoryOwner::NewL(aImplementationInformation);
       
   270     CcaPluginFactoryOwner* factory = iFactoryTempPtr;
       
   271 
       
   272     for(TInt j=0; j < factory->Factory().TabViewCount(); j++)
       
   273         {
       
   274         CCCAppViewPluginBase* plugin = factory->Factory().CreateTabViewL(j);
       
   275         CleanupStack::PushL(plugin);
       
   276         CCCAppPluginData* data = CCCAppPluginData::NewLC(*plugin); //Handles plugin ownership
       
   277         CleanupStack::Pop(2, plugin);
       
   278         CleanupStack::PushL(data);
       
   279         iPluginDataArray.AppendL( data );
       
   280         CleanupStack::Pop(data);
       
   281         data->SetPluginVisibility( CCCAppPluginData::EPluginHidden );
       
   282 
       
   283         //Hand over ownership of factoryOwner (shared ownership among tabs created by factory)
       
   284         factory->AddedChild();
       
   285         plugin->TakeSharedOwnerShip( factory );
       
   286         iFactoryTempPtr = NULL; //ownership given
       
   287         }
       
   288 
       
   289     //If ownership was not given
       
   290     delete iFactoryTempPtr;
       
   291     iFactoryTempPtr = NULL;
       
   292    }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CCCAppPluginLoader::IsSimStoreUri
       
   296 // Determine whether a Contact Store URI is SIM Card storage.
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 TBool CCCAppPluginLoader::IsSimStoreUri( const TVPbkContactStoreUriPtr& aUri ) const
       
   300     {
       
   301     TBool isSimUri(EFalse);
       
   302 
       
   303     isSimUri = !aUri.Compare(VPbkContactStoreUris::SimGlobalAdnUri(),
       
   304                     TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) ||
       
   305                !aUri.Compare(VPbkContactStoreUris::SimGlobalFdnUri(),
       
   306                     TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) ||
       
   307                !aUri.Compare(VPbkContactStoreUris::SimGlobalSdnUri(),
       
   308                     TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) ||
       
   309                !aUri.Compare(VPbkContactStoreUris::SimGlobalOwnNumberUri(),
       
   310                     TVPbkContactStoreUriPtr::EContactStoreUriAllComponents);
       
   311     return isSimUri;
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // CCCAppPluginLoader::IsCurrentContactStoreSupportL
       
   316 // Determine whether an implementation plug-in is supported by Current Contact Store. 
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 TBool CCCAppPluginLoader::IsCurrentContactStoreSupportL( const TInt& aImplmentationUid ) const
       
   320     {
       
   321     TBool isCurrentContactStoreSupport(ETrue);
       
   322 
       
   323     if( ( KCCADetailsViewPluginImplmentationUid != aImplmentationUid )
       
   324             && ( KCCACommLauncherPluginImplmentationUid != aImplmentationUid )
       
   325             && ( KCCAMyCardPluginImplmentationUid != aImplmentationUid ) )
       
   326         {
       
   327         MVPbkContactLink* link = NULL;
       
   328         MVPbkContactLinkArray* contactArray = NULL;
       
   329         HBufC& contactData = iAppEngine->Parameter().ContactDataL();
       
   330         HBufC8* contactData8 = HBufC8::NewLC(contactData.Size());
       
   331         TPtr8 contactData8Ptr(contactData8->Des());
       
   332         contactData8Ptr.Copy(contactData.Des());
       
   333           
       
   334         contactArray = iAppServices->ContactManager().CreateLinksLC(contactData8Ptr);
       
   335 
       
   336         if (contactArray->Count() > 0)
       
   337             {
       
   338             link = contactArray->At(0).CloneLC();
       
   339             }
       
   340 
       
   341         if (link)
       
   342             {
       
   343             const MVPbkContactStoreProperties& storeProperties =
       
   344                     link->ContactStore().StoreProperties();
       
   345             TVPbkContactStoreUriPtr uri = storeProperties.Uri();
       
   346             isCurrentContactStoreSupport = !IsSimStoreUri( uri );
       
   347             }
       
   348             
       
   349 
       
   350         if( link )
       
   351             {
       
   352             CleanupStack::PopAndDestroy(); //link
       
   353             }
       
   354         if( contactArray )
       
   355             {
       
   356             CleanupStack::PopAndDestroy(); //contactArray
       
   357             }
       
   358 
       
   359         CleanupStack::PopAndDestroy(); //contactData8
       
   360         }
       
   361 
       
   362     return isCurrentContactStoreSupport;
       
   363     }
       
   364 
       
   365 // ---------------------------------------------------------------------------
       
   366 // CCCAppPluginLoader::PreparePbk2ApplicationServicesL
       
   367 // ---------------------------------------------------------------------------
       
   368 //
       
   369 void CCCAppPluginLoader::PreparePbk2ApplicationServicesL()
       
   370     {   
       
   371     iCommandsResourceFile.OpenL(
       
   372         KPbk2RomFileDrive, KDC_RESOURCE_FILES_DIR, KPbk2CommandsDllResFileName );
       
   373     iUiControlsResourceFile.OpenL(
       
   374         KPbk2RomFileDrive, KDC_RESOURCE_FILES_DIR, KPbk2UiControlsDllResFileName );
       
   375     iCommonUiResourceFile.OpenL(
       
   376         KPbk2RomFileDrive, KDC_RESOURCE_FILES_DIR, KPbk2CommonUiDllResFileName );
       
   377 
       
   378     iAppServices = CPbk2ApplicationServices::InstanceL();
       
   379     iAppServices->StoreConfiguration().AddObserverL(*this);    
       
   380     }
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // CCCAppPluginLoader::LoadAllPlugins
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 void CCCAppPluginLoader::LoadAllPlugins(
       
   387         const RArray<TCCAPluginsOrderInfo>& aPluginOrderInfoArray, const TDesC8& aPluginProperties )
       
   388     {
       
   389     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::LoadAllPlugins"));
       
   390 
       
   391     const TInt count = aPluginOrderInfoArray.Count();
       
   392     CCA_DP( KCCAppLogFile, CCA_L("::LoadAllPlugins - plugin count: %d"), count );
       
   393     for ( TInt i = 0; i < count; ++i )
       
   394         {
       
   395         TInt tempImplmentationUid = aPluginOrderInfoArray[i].iPluginInfor->ImplementationUid().iUid;
       
   396         TBool isCurrentContactStoreSupport = EFalse;
       
   397         TRAPD( err, isCurrentContactStoreSupport = IsCurrentContactStoreSupportL( tempImplmentationUid ) );
       
   398         if( err != KErrNone || !isCurrentContactStoreSupport )
       
   399             {
       
   400             /* If problems with Contact Link related operations or the Contact Link is in SIM Store,
       
   401              * don't load current plugin. Just continuing
       
   402              * to load the next one. */
       
   403             continue;
       
   404             }
       
   405         /* If problems with plugin loading, that plugin is
       
   406          * not included to the plugin array. Just continuing
       
   407          * and trying to load the next one. */
       
   408         TRAP_IGNORE( CheckAndLoadPluginL(
       
   409                 aPluginOrderInfoArray[i], aPluginProperties ));
       
   410         }
       
   411 
       
   412     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::LoadAllPlugins"));
       
   413     }
       
   414 
       
   415 // ---------------------------------------------------------------------------
       
   416 // CCCAppPluginLoader::CheckAndLoadPluginL
       
   417 // ---------------------------------------------------------------------------
       
   418 //
       
   419 void CCCAppPluginLoader::CheckAndLoadPluginL(
       
   420     const TCCAPluginsOrderInfo& aPluginsOrderInfo,
       
   421     const TDesC8& aPluginProperties )
       
   422     {
       
   423     HBufC8* match = GetmachingPropertiesLC(
       
   424             aPluginsOrderInfo.iPluginInfor->OpaqueData(),
       
   425             aPluginProperties,
       
   426             EFalse );
       
   427     TBool loadThis = match->Length() > 0;
       
   428     CleanupStack::PopAndDestroy(match);
       
   429 
       
   430     //Fallback1 for old plugins that provide only number in opaque data: load them always
       
   431     //The below if{} can be removed when legacy plugins support new format of OpaqueData
       
   432     if(!loadThis)
       
   433         {
       
   434         loadThis = OpaqueValueFrom( *aPluginsOrderInfo.iPluginInfor ) > 0;
       
   435         }
       
   436 
       
   437     if( loadThis )
       
   438         {
       
   439         TUid uid = aPluginsOrderInfo.iPluginInfor->ImplementationUid();
       
   440 
       
   441         if( aPluginsOrderInfo.iOldInterFaceType )
       
   442             {
       
   443             LoadPluginL(uid);   //lecacy implementations
       
   444             }
       
   445         else
       
   446             {
       
   447             LoadOneMultiViewPluginL( aPluginsOrderInfo.iPluginInfor ); //New implementations
       
   448             }
       
   449         CCA_DP( KCCAppLogFile, CCA_L("::LoadAllPlugins - plugin loaded uid: %d"), uid.iUid );
       
   450         }
       
   451     }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // CCCAppPluginLoader::LoadPluginL
       
   455 // ---------------------------------------------------------------------------
       
   456 //
       
   457 void CCCAppPluginLoader::LoadPluginL(
       
   458         TUid aImplementationUid )
       
   459     {
       
   460     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::LoadPluginL"));
       
   461 
       
   462     CCCAppViewPluginBase* plugin =
       
   463             CCCAppViewPluginBase::NewL( aImplementationUid );
       
   464     plugin->SetAppEngine(iAppEngine);
       
   465     CCA_DP( KCCAppLogFile, CCA_L("::LoadPluginL - plugin created"));
       
   466     CleanupStack::PushL( plugin );
       
   467     User::LeaveIfError( aImplementationUid == plugin->Id() ? KErrNone : KErrArgument );
       
   468     CCCAppPluginData* data = CCCAppPluginData::NewLC( *plugin );
       
   469     data->SetPluginVisibility( CCCAppPluginData::EPluginHidden );
       
   470     iPluginDataArray.AppendL( data );
       
   471     CCA_DP( KCCAppLogFile, CCA_L("::LoadPluginL - plugin added to iPluginDataArray"));
       
   472     CleanupStack::Pop( 2, plugin );// data, plugin
       
   473     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::LoadPluginL"));
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------------------------
       
   477 // CCCAppPluginLoader::NextPlugin
       
   478 // ---------------------------------------------------------------------------
       
   479 //
       
   480 CCCAppPluginData* CCCAppPluginLoader::NextPlugin( TBool aOnlyVisiblePlugins )
       
   481     {
       
   482     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::NextPlugin"));
       
   483     CCA_DP( KCCAppLogFile, CCA_L("::NextPlugin - iCurrentPlugin: %d"), iCurrentPlugin );
       
   484 
       
   485     for(TInt i = iCurrentPlugin+1; i < PluginsCount(); i++)
       
   486         {
       
   487         if( !aOnlyVisiblePlugins )
       
   488             {
       
   489             return iPluginDataArray[iCurrentPlugin = i];
       
   490             }
       
   491         else if( iPluginDataArray[i]->PluginVisibility() == CCCAppPluginData::EPluginVisible )
       
   492             {
       
   493             return iPluginDataArray[iCurrentPlugin = i];
       
   494             }
       
   495         }
       
   496         CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::NextPlugin - no next"));
       
   497         return NULL;
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 // CCCAppPluginLoader::PreviousPlugin
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 CCCAppPluginData* CCCAppPluginLoader::PreviousPlugin( TBool aOnlyVisiblePlugins )
       
   505     {
       
   506     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::PreviousPlugin"));
       
   507     CCA_DP( KCCAppLogFile, CCA_L("::PreviousPlugin - iCurrentPlugin: %d"), iCurrentPlugin );
       
   508 
       
   509     for(TInt i = iCurrentPlugin-1; i >= 0; i--)
       
   510         {
       
   511         if( !aOnlyVisiblePlugins )
       
   512             {
       
   513             return iPluginDataArray[iCurrentPlugin = i];
       
   514             }
       
   515         else if( iPluginDataArray[i]->PluginVisibility() == CCCAppPluginData::EPluginVisible )
       
   516             {
       
   517             return iPluginDataArray[iCurrentPlugin = i];
       
   518             }
       
   519         }
       
   520         CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::PreviousPlugin - no previous"));
       
   521         return NULL;
       
   522     }
       
   523 
       
   524 // ---------------------------------------------------------------------------
       
   525 // CCCAppPluginLoader::SetPluginInFocus
       
   526 // ---------------------------------------------------------------------------
       
   527 //
       
   528 TInt CCCAppPluginLoader::SetPluginInFocus( const TUid aUid )
       
   529     {
       
   530     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::SetPluginInFocus"));
       
   531     CCA_DP( KCCAppLogFile, CCA_L("::SetPluginInFocus - searching aUid: %d"), aUid );
       
   532 
       
   533     TInt index = KErrNotFound;
       
   534     // no need to search if no uid provided
       
   535     if ( TUid::Null() == aUid )
       
   536         return index;
       
   537 
       
   538     const TInt count = iPluginDataArray.Count();
       
   539     CCA_DP( KCCAppLogFile, CCA_L("::SetPluginInFocus - plugin count: %d"), count );
       
   540     for ( TInt i = 0; i < count; ++i )
       
   541         {
       
   542         TUid uid( iPluginDataArray[i]->Plugin().Id() );
       
   543         CCA_DP( KCCAppLogFile, CCA_L("::SetPluginInFocus - uid: %d found"), uid );
       
   544         if( aUid == uid )
       
   545             {
       
   546             index = i;
       
   547             iCurrentPlugin = i;
       
   548             break;// found, no need to loop all through
       
   549             }
       
   550         }
       
   551     CCA_DP( KCCAppLogFile, CCA_L("::SetPluginInFocus - index after searching the array %d"), index );
       
   552     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::SetPluginInFocus"));
       
   553     return index;
       
   554     }
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 // CCCAppPluginLoader::PluginInFocus
       
   558 // ---------------------------------------------------------------------------
       
   559 //
       
   560 CCCAppPluginData* CCCAppPluginLoader::PluginInFocus( )
       
   561     {
       
   562     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::PluginInFocus"));
       
   563     CCA_DP( KCCAppLogFile, CCA_L("::PluginInFocus - iCurrentPlugin: %d"), iCurrentPlugin );
       
   564 
       
   565     if ( 0 > iCurrentPlugin || iCurrentPlugin > PluginsCount()-1 )
       
   566         {
       
   567         CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::PluginInFocus - not in range"));
       
   568         return NULL;
       
   569         }
       
   570     else
       
   571         {
       
   572         CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::PluginInFocus - found in range"));
       
   573         return iPluginDataArray[ iCurrentPlugin ];
       
   574         }
       
   575     }
       
   576 
       
   577 // ---------------------------------------------------------------------------
       
   578 // CCCAppPluginLoader::PluginsCount
       
   579 // ---------------------------------------------------------------------------
       
   580 //
       
   581 TInt CCCAppPluginLoader::PluginsCount( ) const
       
   582     {
       
   583     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::PluginsCount"));
       
   584     const TInt count = iPluginDataArray.Count();
       
   585     CCA_DP( KCCAppLogFile, CCA_L("::PluginsCount - count %d"), count );
       
   586     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::PluginsCount"));
       
   587     return count;
       
   588     }
       
   589 
       
   590 // ---------------------------------------------------------------------------
       
   591 // CCCAppPluginLoader::VisiblePluginCount
       
   592 // ---------------------------------------------------------------------------
       
   593 //
       
   594 TInt CCCAppPluginLoader::VisiblePluginCount( ) const
       
   595     {
       
   596     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::VisiblePluginCount"));
       
   597     TInt count(0);
       
   598     for(TInt i = 0; i < iPluginDataArray.Count(); i++ )
       
   599         {
       
   600         CCCAppPluginData* dta = iPluginDataArray[i];
       
   601         if( dta->PluginVisibility() == CCCAppPluginData::EPluginVisible)
       
   602             {
       
   603             count++;
       
   604             }
       
   605         }
       
   606 
       
   607     CCA_DP( KCCAppLogFile, CCA_L("::VisiblePluginCount - count %d"), count );
       
   608     CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::VisiblePluginCount"));
       
   609     return count;
       
   610     }
       
   611 
       
   612 
       
   613 // ---------------------------------------------------------------------------
       
   614 // CCCAppPluginLoader::VisiblePlugin
       
   615 // ---------------------------------------------------------------------------
       
   616 //
       
   617 CCCAppPluginData* CCCAppPluginLoader::VisiblePlugin( TInt aIndex, TBool aChangefocus )
       
   618     {
       
   619     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::VisiblePluginAt"));
       
   620     CCA_DP( KCCAppLogFile, CCA_L("::VisiblePluginAt - aIndex %d"), aIndex );
       
   621     TInt visiblePlugin(KErrNotFound);
       
   622 
       
   623     for(TInt i = 0; i < PluginsCount(); i++)
       
   624         {
       
   625         if( iPluginDataArray[i]->PluginVisibility() == CCCAppPluginData::EPluginVisible )
       
   626             {
       
   627             visiblePlugin++;
       
   628             }
       
   629         if( visiblePlugin == aIndex )
       
   630             {
       
   631             CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::VisiblePluginAt - found in range"));
       
   632             return PluginAt( i, aChangefocus );
       
   633             }
       
   634         }
       
   635         CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::VisiblePluginAt - not in visible range"));
       
   636         return NULL;
       
   637     }
       
   638 
       
   639 
       
   640 // ---------------------------------------------------------------------------
       
   641 // CCCAppPluginLoader::PluginAt
       
   642 // ---------------------------------------------------------------------------
       
   643 //
       
   644 CCCAppPluginData* CCCAppPluginLoader::PluginAt( TInt aIndex, TBool aChangefocus )
       
   645     {
       
   646     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::PluginAt"));
       
   647     CCA_DP( KCCAppLogFile, CCA_L("::PluginAt - aIndex %d"), aIndex );
       
   648 
       
   649     const TInt count = PluginsCount();
       
   650     if ( 0 == count || 0 > aIndex || (count - 1) < aIndex )
       
   651         {
       
   652         CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::PluginAt - not in range"));
       
   653         return NULL;
       
   654         }
       
   655     else
       
   656         {
       
   657         CCA_DP( KCCAppLogFile, CCA_L("<-CCCAppPluginData::PluginAt - found in range"));
       
   658         if ( aChangefocus )
       
   659             iCurrentPlugin = aIndex;
       
   660         return iPluginDataArray[ aIndex ];
       
   661         }
       
   662     }
       
   663 
       
   664 // ---------------------------------------------------------------------------
       
   665 // CCCAppPluginLoader::RemovePlugin
       
   666 // ---------------------------------------------------------------------------
       
   667 //
       
   668 void CCCAppPluginLoader::RemovePlugin( TUid aPlugin )
       
   669     {
       
   670     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::RemovePlugin"));
       
   671     CCA_DP( KCCAppLogFile, CCA_L("::RemovePlugin - aPlugin %d"), aPlugin );
       
   672 
       
   673     TInt count = PluginsCount();
       
   674 
       
   675     for ( TInt i = 0; i < count; ++i )
       
   676         {
       
   677         TUid id = iPluginDataArray[ i ]->Plugin().Id();
       
   678         if( aPlugin == id )
       
   679             {
       
   680             // delete
       
   681             delete iPluginDataArray[ i ];
       
   682             iPluginDataArray.Remove( i );
       
   683             break;
       
   684             }
       
   685         }
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------------------------
       
   689 // CCCAppPluginLoader::Plugin
       
   690 // ---------------------------------------------------------------------------
       
   691 //
       
   692 CCCAppViewPluginBase* CCCAppPluginLoader::Plugin( TUid aPlugin )
       
   693     {
       
   694     CCA_DP( KCCAppLogFile, CCA_L("->CCCAppPluginData::Plugin"));
       
   695     CCA_DP( KCCAppLogFile, CCA_L("::Plugin - aPlugin %d"), aPlugin );
       
   696 
       
   697     TInt count = PluginsCount();
       
   698 
       
   699     for ( TInt i = 0; i < count; ++i )
       
   700         {
       
   701         TUid id = iPluginDataArray[ i ]->Plugin().Id();
       
   702         if( aPlugin == id )
       
   703             {
       
   704             return &(iPluginDataArray[ i ]->Plugin());
       
   705             }
       
   706         }
       
   707     return NULL;
       
   708     }
       
   709 
       
   710 // ---------------------------------------------------------------------------
       
   711 // CCCAppPluginLoader::SetPluginVisibility
       
   712 // ---------------------------------------------------------------------------
       
   713 //
       
   714 TBool CCCAppPluginLoader::SetPluginVisibility(
       
   715     TUid aPlugin,
       
   716     TInt aVisibility)
       
   717     {
       
   718     TBool ret(EFalse);
       
   719     const TInt count = iPluginDataArray.Count();
       
   720     CCA_DP( KCCAppLogFile, CCA_L("::SetPluginVisibility - plugin count: %d"), count );
       
   721     for ( TInt i = 0; i < count; i++ )
       
   722         {
       
   723         TUid uid( iPluginDataArray[i]->Plugin().Id() );
       
   724         if( aPlugin == uid )
       
   725             {
       
   726             if( aVisibility != iPluginDataArray[i]->PluginVisibility() )
       
   727                 {
       
   728                 iPluginDataArray[i]->SetPluginVisibility( aVisibility );
       
   729                 ret = ETrue;
       
   730                 }
       
   731 
       
   732             break;
       
   733             }
       
   734         }
       
   735     return ret;
       
   736     }
       
   737 
       
   738 // ---------------------------------------------------------------------------
       
   739 // CCCAppPluginLoader::SetPluginVisibility
       
   740 // ---------------------------------------------------------------------------
       
   741 //
       
   742 TInt CCCAppPluginLoader::PluginVisibility(
       
   743     TUid aPlugin, TInt& aTabNbr )
       
   744     {
       
   745     TInt visibility(KErrNotFound);
       
   746     TInt tabNbr(KErrNotFound);
       
   747     const TInt count = iPluginDataArray.Count();
       
   748     CCA_DP( KCCAppLogFile, CCA_L("::SetPluginVisibility - plugin count: %d"), count );
       
   749 
       
   750     for ( TInt i = 0; i < count; i++ )
       
   751         {
       
   752         if(iPluginDataArray[i]->PluginVisibility() == CCCAppPluginData::EPluginVisible)
       
   753             {
       
   754             tabNbr++;
       
   755             }
       
   756         TUid uid( iPluginDataArray[i]->Plugin().Id() );
       
   757         if( aPlugin == uid )
       
   758             {
       
   759             visibility = iPluginDataArray[i]->PluginVisibility();
       
   760             if(visibility == CCCAppPluginData::EPluginVisible)
       
   761                 {
       
   762                 aTabNbr = tabNbr;
       
   763                 }
       
   764             break;
       
   765             }
       
   766         }
       
   767     return visibility;
       
   768     }
       
   769 
       
   770 // ---------------------------------------------------------------------------
       
   771 // CCCAppPluginLoader::GetPbksXPExtesionNamesL
       
   772 // ---------------------------------------------------------------------------
       
   773 //
       
   774 void CCCAppPluginLoader::GetPbksXPExtesionNamesL( RArray<TPtrC>& aPbksXPExtesionNamesArray,
       
   775         const TDesC& aNameString)
       
   776     {
       
   777     CleanupClosePushL( aPbksXPExtesionNamesArray );
       
   778     TLex nameString ( aNameString );
       
   779     TChar curChar;
       
   780     nameString.Mark();
       
   781     while( !nameString.Eos() )
       
   782         {
       
   783         curChar = nameString.Peek();
       
   784         if( curChar == '|' )
       
   785             {
       
   786             TPtrC extractedName = nameString.MarkedToken();
       
   787             User::LeaveIfError(aPbksXPExtesionNamesArray.Append(extractedName));
       
   788 
       
   789             nameString.Inc();
       
   790             nameString.Mark();
       
   791             }
       
   792         else
       
   793             {
       
   794             nameString.Inc();
       
   795             }
       
   796         }
       
   797     CleanupStack::Pop();
       
   798     }
       
   799 
       
   800 // ---------------------------------------------------------------------------
       
   801 // CCCAppPluginLoader::LargestOpaqueFromInHousePlugins
       
   802 // ---------------------------------------------------------------------------
       
   803 //
       
   804 TInt CCCAppPluginLoader::LargestOpaqueFromInHousePlugins( RArray<TCCAPluginsOrderInfo>& aOrderInfoArray )
       
   805     {
       
   806     TInt largestOpaqueFromInHouse = 0;
       
   807     for ( TInt i=0; i<aOrderInfoArray.Count(); i++ )
       
   808         {
       
   809         // this is for plugins in group ECCAInHousePlugins, the purpose of doing this
       
   810         // is find start position for plugins in group ECCAPlugindInBothCCAAndNameList.
       
   811         // this means if opaque values in group ECCAInHousePlugins are negative,
       
   812         // Initial value if largestOpaqueFromInHouse 0 will be taked to be used.
       
   813         // if they are positive values, find the largest
       
   814         TInt order = aOrderInfoArray[i].iOrder;
       
   815         if (aOrderInfoArray[i].iGroupInfo == TCCAPluginsOrderInfo::ECCAInHousePlugins &&
       
   816                 order > largestOpaqueFromInHouse )
       
   817             {
       
   818             largestOpaqueFromInHouse = order;
       
   819             }
       
   820         }
       
   821     return largestOpaqueFromInHouse;
       
   822     }
       
   823 
       
   824 // ---------------------------------------------------------------------------
       
   825 // CCCAppPluginLoader::SmallestOpaqueFromPluginsOnlyInCCA
       
   826 // ---------------------------------------------------------------------------
       
   827 //
       
   828 TInt CCCAppPluginLoader::SmallestOpaqueFromPluginsOnlyInCCA( RArray<TCCAPluginsOrderInfo>& aOrderInfoArray )
       
   829     {
       
   830     TInt smallestOpaque = 0;
       
   831     for ( TInt i=0; i<aOrderInfoArray.Count(); i++ )
       
   832         {
       
   833         // for plugins in group ECCAPlugindInBothCCAAndNameList, orders are follow as
       
   834         // corresponding sXPextension in  Name List view.
       
   835 
       
   836         // this is for plugins in group ECCAPluginsOnlyInCCA. the purpose of doing this is
       
   837         // find start positions for plugins in group ECCAPluginsOnlyInCCA if there is negative
       
   838         // opaque value. if no negative values, the start postion of plugins in this
       
   839         // ECCAPluginsOnlyInCCA group should follow the last one's opaque value in group
       
   840         // ECCAPlugindInBothCCAAndNameList
       
   841         TInt order = aOrderInfoArray[i].iOrder;
       
   842         if (aOrderInfoArray[i].iGroupInfo == TCCAPluginsOrderInfo::ECCAPluginsOnlyInCCA &&
       
   843                 order < smallestOpaque )
       
   844             {
       
   845             smallestOpaque = order;
       
   846             }
       
   847         }
       
   848     return smallestOpaque;
       
   849     }
       
   850 
       
   851 // ---------------------------------------------------------------------------
       
   852 // CCCAppPluginLoader::UpdateOrdersForPluginsOnlyInCCA
       
   853 // ---------------------------------------------------------------------------
       
   854 //
       
   855 void CCCAppPluginLoader::UpdateOrdersForPluginsOnlyInCCA(
       
   856         const TInt aStartPosition,
       
   857         RArray<TCCAPluginsOrderInfo>& aOrderInfoArray)
       
   858     {
       
   859     for ( TInt i=0; i<aOrderInfoArray.Count(); i++ )
       
   860         {
       
   861         if( aOrderInfoArray[i].iGroupInfo == TCCAPluginsOrderInfo::ECCAPluginsOnlyInCCA )
       
   862           {
       
   863           aOrderInfoArray[i].iOrder = aOrderInfoArray[i].iOrder + aStartPosition;
       
   864           }
       
   865         }
       
   866     }
       
   867 
       
   868 // ---------------------------------------------------------------------------
       
   869 // CCCAppPluginLoader::UpdateOrdersForPluginsInBothCCAAndNameList
       
   870 // ---------------------------------------------------------------------------
       
   871 //
       
   872 void CCCAppPluginLoader::UpdateOrdersForPluginsInBothCCAAndNameList(
       
   873         TInt& aLastPosition,
       
   874         RArray<TCCAPluginsOrderInfo>& aOrderInfoArray,
       
   875         const RArray<TPtrC>& aNameListPluginNameArray)
       
   876     {
       
   877     // go through phonebook main view's sXP Extension plugins name list
       
   878     // Group2 means ECCAPlugindInBothCCAAndNameList
       
   879     TInt startPosition = aLastPosition;
       
   880     for ( TInt i=0; i<aNameListPluginNameArray.Count(); i++ )
       
   881        {
       
   882        TInt found = EFalse;
       
   883        for ( TInt j=0; j<aOrderInfoArray.Count() && !found; j++ )
       
   884            {
       
   885            if( aNameListPluginNameArray[i].CompareF(aOrderInfoArray[j].iPluginInfor->DisplayName()) == 0
       
   886                    && aOrderInfoArray[j].iGroupInfo == TCCAPluginsOrderInfo::ECCAPlugindInBothCCAAndNameList )
       
   887                {
       
   888                aOrderInfoArray[j].iOrder = startPosition + 1 + i;
       
   889                aLastPosition = aOrderInfoArray[j].iOrder;
       
   890                found = ETrue;
       
   891                }
       
   892            }
       
   893        }
       
   894 
       
   895     }
       
   896 
       
   897 // ---------------------------------------------------------------------------
       
   898 // CCCAppPluginLoader::SortPluginsOrderInfoL
       
   899 // ---------------------------------------------------------------------------
       
   900 //
       
   901 void CCCAppPluginLoader::SortPluginsOrderInfoL( RArray<TCCAPluginsOrderInfo>& aOrderInfoArray,
       
   902         const RArray<TPtrC>& aNameListPluginNameArray)
       
   903     {
       
   904     // largest opaque from in-house plugins
       
   905     TInt largestOpaqueFromGroup1 = LargestOpaqueFromInHousePlugins(aOrderInfoArray);
       
   906 
       
   907     // go through phonebook main view's sXP Extension plugins name list
       
   908     // Group2 means ECCAPlugindInBothCCAAndNameList
       
   909     TInt lastPosInGroup2 = largestOpaqueFromGroup1 + 1;
       
   910 
       
   911     UpdateOrdersForPluginsInBothCCAAndNameList(lastPosInGroup2, aOrderInfoArray, aNameListPluginNameArray);
       
   912 
       
   913     // Group3 means ECCAPluginsOnlyInCCA
       
   914     TInt startPosInGroup3 = lastPosInGroup2 + 1;
       
   915 
       
   916     // smallest opaque from ECCAPluginsOnlyInCCA
       
   917     TInt smallestOpaqueFromGroup3 = SmallestOpaqueFromPluginsOnlyInCCA(aOrderInfoArray);
       
   918 
       
   919     // if there are negative opaque values from group3
       
   920     if (smallestOpaqueFromGroup3 < 0)
       
   921         {
       
   922         startPosInGroup3 = startPosInGroup3 - smallestOpaqueFromGroup3;
       
   923         }
       
   924 
       
   925     UpdateOrdersForPluginsOnlyInCCA(startPosInGroup3, aOrderInfoArray);
       
   926 
       
   927     // after opaque value(iOrder) has been handled for each of three group:
       
   928     // ECCAInHousePlugins, ECCAPlugindInBothCCAAndNameList and ECCAPluginsOnlyInCCA
       
   929     // finally sort the aOrderInfoArray by iOrder
       
   930     TLinearOrder< TCCAPluginsOrderInfo > order( *TCCAPluginsOrderInfo::SortByOrder );
       
   931     aOrderInfoArray.Sort( order );
       
   932     }
       
   933 
       
   934 // ---------------------------------------------------------------------------
       
   935 // CCCAppPluginLoader::FindPluginNameFromNameListByCCAPluginInfo
       
   936 // ---------------------------------------------------------------------------
       
   937 //
       
   938 TInt CCCAppPluginLoader::FindPluginNameFromNameListByCCAPluginInfo(
       
   939         const CImplementationInformation& aCCAPluginInfo,
       
   940         const RArray<TPtrC>& aNameListPluginNameArray)
       
   941     {
       
   942     TInt result = KErrNotFound;
       
   943     for ( TInt i=0; i<aNameListPluginNameArray.Count() && result == KErrNotFound; i++ )
       
   944         {
       
   945         if( aNameListPluginNameArray[i].CompareF( aCCAPluginInfo.DisplayName())==0 )
       
   946             {
       
   947             result = i;
       
   948             }
       
   949         }
       
   950     return result;
       
   951     }
       
   952 
       
   953 // ---------------------------------------------------------------------------
       
   954 // CCCAppPluginLoader::GetPluginsInfoL
       
   955 // ---------------------------------------------------------------------------
       
   956 //
       
   957 void CCCAppPluginLoader::GetPluginsInfoL( RArray<TCCAPluginsOrderInfo>& aOrderInfoArray,
       
   958         const RArray<TPtrC>& aNameListPluginNameArray,
       
   959         RPointerArray<CImplementationInformation>& aOldPluginInfoArray,
       
   960         RPointerArray<CImplementationInformation>& aNewPluginInfoArray)
       
   961     {
       
   962     //1. For lecagy interface implementations
       
   963     AppendOrderInfoL( aOrderInfoArray, aNameListPluginNameArray,
       
   964             aOldPluginInfoArray, ETrue );
       
   965 
       
   966     //2. For new interface implementations
       
   967     AppendOrderInfoL( aOrderInfoArray, aNameListPluginNameArray,
       
   968             aNewPluginInfoArray, EFalse );
       
   969     }
       
   970 
       
   971 // ---------------------------------------------------------------------------
       
   972 // CCCAppPluginLoader::AppendOrderInfoL
       
   973 // ---------------------------------------------------------------------------
       
   974 //
       
   975 void CCCAppPluginLoader::AppendOrderInfoL( RArray<TCCAPluginsOrderInfo>& aOrderInfoArray,
       
   976         const RArray<TPtrC>& aNameListPluginNameArray,
       
   977         RPointerArray<CImplementationInformation>& aPluginInfoArray,
       
   978         TBool aIsOldInterFaceType)
       
   979     {
       
   980     // copy object CImplementationInformation's address from aPluginInfoArray to pluginOrderInfo
       
   981     // copy object CImplementationInformation's opaque value to pluginOrderInfo
       
   982     // give identification of TCCAPluginGroup info for each object in pluginOrderInfo
       
   983     for ( TInt i=0; i<aPluginInfoArray.Count(); i++ )
       
   984         {
       
   985         TCCAPluginsOrderInfo pluginOrderInfo;
       
   986         pluginOrderInfo.iPluginInfor = aPluginInfoArray[i];
       
   987         pluginOrderInfo.iOrder = GetOrderValueL( *aPluginInfoArray[i] );
       
   988 
       
   989         //in-house CCA plugins impelemented by ourself
       
   990         if (aPluginInfoArray[i]->ImplementationUid()==TUid::Uid(KCCACommLauncherPluginImplmentationUid) ||
       
   991             aPluginInfoArray[i]->ImplementationUid()== TUid::Uid(KCCADetailsViewPluginImplmentationUid))
       
   992             {
       
   993             pluginOrderInfo.iGroupInfo = TCCAPluginsOrderInfo::ECCAInHousePlugins;
       
   994             }
       
   995         // CCA plugin name found from plugin name list of phonebook main view's sXPExtensions
       
   996         else if (FindPluginNameFromNameListByCCAPluginInfo(*aPluginInfoArray[i],aNameListPluginNameArray) != KErrNotFound )
       
   997             {
       
   998             pluginOrderInfo.iGroupInfo = TCCAPluginsOrderInfo::ECCAPlugindInBothCCAAndNameList;
       
   999             }
       
  1000         // CCA plugin name is not found from plugin name list of phonebook main view's sXPExtensions
       
  1001         else
       
  1002             {
       
  1003             pluginOrderInfo.iGroupInfo = TCCAPluginsOrderInfo::ECCAPluginsOnlyInCCA;
       
  1004             }
       
  1005 
       
  1006         pluginOrderInfo.iOldInterFaceType = aIsOldInterFaceType;
       
  1007         User::LeaveIfError(aOrderInfoArray.Append( pluginOrderInfo ));
       
  1008         }
       
  1009     }
       
  1010 
       
  1011 // ---------------------------------------------------------------------------
       
  1012 // CCCAppPluginLoader::GetOrderValueL
       
  1013 // ---------------------------------------------------------------------------
       
  1014 //
       
  1015 TInt CCCAppPluginLoader::GetOrderValueL( const CImplementationInformation& aInfo )
       
  1016     {
       
  1017     HBufC8* match = GetmachingPropertiesLC(
       
  1018         aInfo.OpaqueData(), TPtrC8(KCcaOpaqueTABP), EFalse);
       
  1019     TPtrC8 namePtr;
       
  1020     TPtrC8 valuePtr;
       
  1021     TPtrC8 mp(*match);
       
  1022     GetNameValue( namePtr, valuePtr, mp);
       
  1023     TInt order = 0;
       
  1024     TLex8 lex( valuePtr );
       
  1025     lex.Val( order );
       
  1026     CleanupStack::PopAndDestroy(match);
       
  1027 
       
  1028     //Fallback2 for old plugins that provide only number in opaque data:
       
  1029     //The below if{} can be removed when all plugins provide new format OpaqueData
       
  1030     if(!order)
       
  1031         {
       
  1032         order = OpaqueValueFrom( aInfo );
       
  1033         }
       
  1034 
       
  1035     return order;
       
  1036     }
       
  1037 
       
  1038 // ---------------------------------------------------------------------------
       
  1039 // CCCAppPluginLoader::OpaqueValueFrom
       
  1040 // ---------------------------------------------------------------------------
       
  1041 //
       
  1042 TInt CCCAppPluginLoader::OpaqueValueFrom( const CImplementationInformation& aInfo )
       
  1043     {
       
  1044     TInt opaqueValue = 0;
       
  1045 
       
  1046     TLex8 lex( aInfo.OpaqueData() );
       
  1047     lex.Val( opaqueValue );
       
  1048 
       
  1049     return opaqueValue;
       
  1050     }
       
  1051 
       
  1052 // ----------------------------------------------------------------------------
       
  1053 // CCCAppPluginLoader::GetmachingPropertiesLC
       
  1054 // ----------------------------------------------------------------------------
       
  1055 //
       
  1056 HBufC8* CCCAppPluginLoader::GetmachingPropertiesLC(
       
  1057     const TDesC8& aData, const TDesC8& aDataRef, TBool aMatchValuesToo)
       
  1058     {
       
  1059     TPtrC8 dataPtr(aData);
       
  1060     HBufC8* foundData = HBufC8::NewLC( Max(aData.Length(), aDataRef.Length()) );
       
  1061     TPtr8 foundPtr = foundData->Des();
       
  1062 
       
  1063     while( dataPtr.Length() > 0 )
       
  1064         {
       
  1065         TPtrC8 name;
       
  1066         TPtrC8 value;
       
  1067         GetNameValue( name, value, dataPtr);
       
  1068         TPtrC8 dataRefPtr(aDataRef);
       
  1069 
       
  1070         while( name.Length() > 0 && dataRefPtr.Length() > 0 )
       
  1071             {
       
  1072             TPtrC8 nameRef;
       
  1073             TPtrC8 valueRef;
       
  1074             GetNameValue( nameRef, valueRef, dataRefPtr);
       
  1075             TBool nameOk  = !name.Compare(nameRef);
       
  1076             TBool valueOk = aMatchValuesToo ? !value.Compare(valueRef) : ETrue;
       
  1077 
       
  1078             if(nameOk && valueOk)
       
  1079                 {
       
  1080                 foundPtr.Append(name);
       
  1081                 if(value.Length())
       
  1082                     {
       
  1083                     foundPtr.Append(KCcaOpaqueValueDelimiter);
       
  1084                     foundPtr.Append(value);
       
  1085                     }
       
  1086                 foundPtr.Append(KCcaOpaqueNameDelimiter);
       
  1087                 }
       
  1088             }
       
  1089         }
       
  1090     return foundData;
       
  1091     }
       
  1092 
       
  1093 
       
  1094 // ----------------------------------------------------------------------------
       
  1095 // CCCAppPluginLoader::GetNameValue
       
  1096 // Extracted data is removed from property string
       
  1097 // ----------------------------------------------------------------------------
       
  1098 //
       
  1099 void CCCAppPluginLoader::GetNameValue(
       
  1100     TPtrC8& aName, TPtrC8& aValue, TPtrC8& aDataPtr )
       
  1101     {
       
  1102     TInt nextTokenStart = aDataPtr.Find( KCcaOpaqueNameDelimiter );
       
  1103     TPtrC8 delim( aDataPtr );
       
  1104 
       
  1105     if( nextTokenStart > aDataPtr.Length() || nextTokenStart < 0 )
       
  1106         {
       
  1107         nextTokenStart = aDataPtr.Length();
       
  1108         }
       
  1109 
       
  1110     //Inspect on the left side of field delimiter token
       
  1111     TPtrC8 nameValue = aDataPtr.Left( nextTokenStart );
       
  1112     TInt delimiterStart = nameValue.Find( KCcaOpaqueValueDelimiter );
       
  1113     if( delimiterStart > aDataPtr.Length() || delimiterStart < 0 )
       
  1114         {
       
  1115         aName.Set( nameValue );
       
  1116         }
       
  1117     else
       
  1118         {
       
  1119         aName.Set( aDataPtr.Left( delimiterStart ) );
       
  1120         TInt length = nameValue.Length() - delimiterStart - 1;
       
  1121         aValue.Set( aDataPtr.Mid( delimiterStart + 1, length) );
       
  1122         }
       
  1123 
       
  1124     //Remaining data on the right side of token
       
  1125     TInt dataLeft = aDataPtr.Length() - nextTokenStart -1;
       
  1126     if( dataLeft > 0 )
       
  1127         {
       
  1128         //Continue with remaining data on the right side of token
       
  1129         aDataPtr.Set( aDataPtr.Right(dataLeft) );
       
  1130         }
       
  1131     else
       
  1132         {
       
  1133         aDataPtr.Set( TPtrC8() );
       
  1134         }
       
  1135     }
       
  1136 
       
  1137 // ----------------------------------------------------------------------------
       
  1138 // CCCAppPluginLoader::ConfigurationChanged
       
  1139 // ----------------------------------------------------------------------------
       
  1140 //
       
  1141 void CCCAppPluginLoader::ConfigurationChanged()
       
  1142     {
       
  1143     //Special case. Store configuration changed, e.g. store containing current 
       
  1144     //contact removed. So close CCA as current contact may not anymore be available
       
  1145     CAknAppUi* appUi = static_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
       
  1146     TRAP_IGNORE(appUi->HandleCommandL(EAknCmdExit));
       
  1147     }
       
  1148 
       
  1149 // ----------------------------------------------------------------------------
       
  1150 // CCCAppPluginLoader::ConfigurationChangedComplete
       
  1151 // ----------------------------------------------------------------------------
       
  1152 //
       
  1153 void CCCAppPluginLoader::ConfigurationChangedComplete()
       
  1154     {
       
  1155     }
       
  1156 
       
  1157 // End of File