calendarui/customisationmanager/src/calencustomisationmanager.cpp
changeset 0 f979ecb2b13e
child 20 9c5b1510919f
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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:  Handles loading of Calendar customisation plugins
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <eikmenup.h>
       
    20 #include <ecom/ecom.h>
       
    21 #include <Calendar.rsg>
       
    22 #include <aknsettingitemlist.h>          // CAknSettingItem
       
    23 #include <calencommandhandler.h>
       
    24 #include <calencustomisation.h>
       
    25 #include <calenservices.h>
       
    26 #include <mcalenpreview.h>
       
    27 
       
    28 #include "calensend.h"
       
    29 #include "calenviewinfo.h"
       
    30 #include "calendarui_debug.h"
       
    31 #include "calencustomisationmanager.h"
       
    32 #include "calencontroller.h"
       
    33 #include "calensetting.h"
       
    34 #include "CalenUid.h"
       
    35 
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // CCalenCustomisationManager::NewL
       
    39 // Two phased constructor
       
    40 // (other items were commented in a header).
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 EXPORT_C CCalenCustomisationManager* CCalenCustomisationManager::NewL( 
       
    44                                     MCalenServicesFactory& aFactory,
       
    45                                     CCalenPluginStatusArray& aPluginSettingsStatus,
       
    46                                     MCalenServices& aServices,
       
    47                                     RPointerArray<CCalenViewInfo>& aViewArray )
       
    48     {
       
    49     TRACE_ENTRY_POINT;
       
    50 
       
    51     CCalenCustomisationManager* self = new( ELeave ) CCalenCustomisationManager(
       
    52                                                                  aFactory,
       
    53                                                                  aServices,
       
    54                                                                  aViewArray,
       
    55                                                                  aPluginSettingsStatus );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59 
       
    60     TRACE_EXIT_POINT;
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ----------------------------------------------------------------------------
       
    65 // CCalenCustomisationManager::CCalenCustomisationManager
       
    66 // C++ constructor
       
    67 // (other items were commented in a header).
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 CCalenCustomisationManager::CCalenCustomisationManager( MCalenServicesFactory& aFactory,
       
    71                                                         MCalenServices& aServices,
       
    72                                                         RPointerArray<CCalenViewInfo>& aViewArray,
       
    73                                                         CCalenPluginStatusArray& aPluginSettingsStatus )
       
    74     : iServicesFactory( aFactory ),
       
    75       iViewInfoArray( aViewArray ),
       
    76       iSortOrder( CCalenViewInfo::CyclePositionComparison ), 
       
    77       iServices( aServices ),
       
    78       iPluginSettingsStatus( aPluginSettingsStatus )
       
    79     {
       
    80     TRACE_ENTRY_POINT;
       
    81     TRACE_EXIT_POINT;
       
    82     }
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // CCalenCustomisationManager::ConstructL
       
    86 // Second stage constructor
       
    87 // (other items were commented in a header).
       
    88 // ----------------------------------------------------------------------------
       
    89 //
       
    90 void CCalenCustomisationManager::ConstructL()
       
    91     {
       
    92     TRACE_ENTRY_POINT;
       
    93     iInfoBarProviderUid = TUid::Uid(0);
       
    94     iPreviewPaneProviderUid = TUid::Uid(0);
       
    95     
       
    96     // Get a pointer to the global data and controller
       
    97     iGlobalData = CCalenGlobalData::InstanceL();
       
    98     
       
    99     // Get the setting singleton. We update it when settings change.
       
   100     iSetting = CCalenSetting::InstanceL();
       
   101     
       
   102     CreateActivePluginListL();
       
   103 
       
   104     // Load any enabled plugins
       
   105     DoImmediatePluginLoadingL();
       
   106 
       
   107     TRACE_EXIT_POINT;
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------------------------------
       
   111 // CCalenCustomisationManager::~CCalenCustomisationManager
       
   112 // Destructor
       
   113 // (other items were commented in a header).
       
   114 // ----------------------------------------------------------------------------
       
   115 //
       
   116 EXPORT_C CCalenCustomisationManager::~CCalenCustomisationManager()
       
   117     {
       
   118     TRACE_ENTRY_POINT;
       
   119 
       
   120     // Reset and destroy the contents of the owned arrays,
       
   121     // this will delete the plugins.
       
   122     iPlugins.ResetAndDestroy();
       
   123 
       
   124     iPluginInfo.ResetAndDestroy();
       
   125 
       
   126     iActivePlugins.Reset();
       
   127     iRomBasedPlugins.Reset();
       
   128 
       
   129     // reset deferred unload plugins list
       
   130     iDefferedUnloadPluginList.Reset();
       
   131 	
       
   132 	
       
   133     // Close the ECOM interface
       
   134     REComSession::FinalClose();
       
   135 
       
   136     // Release the global data and controller
       
   137     if ( iGlobalData )
       
   138         {
       
   139         iGlobalData->Release();
       
   140         }
       
   141     
       
   142     if(iSetting)
       
   143         {
       
   144         iSetting->Release();
       
   145         }
       
   146     iHiddenViews.Reset();
       
   147     iDefferedUnloadPluginList.Reset();
       
   148 
       
   149     TRACE_EXIT_POINT;
       
   150     }
       
   151 
       
   152 // ----------------------------------------------------------------------------
       
   153 // CCalenCustomisationManager::GetCommandHandlerL
       
   154 // Get a command handler for a specific command.  Ownership remains with the
       
   155 // plugin
       
   156 // ----------------------------------------------------------------------------
       
   157 EXPORT_C MCalenCommandHandler* CCalenCustomisationManager::GetCommandHandlerL( TInt aCommand )
       
   158     {
       
   159     TRACE_ENTRY_POINT;
       
   160 
       
   161     MCalenCommandHandler* handler( NULL );
       
   162     
       
   163     // Loop though all the enabled plugins asking for a command handler
       
   164     // to handle this command with.  Returns NULL if no plugin wants to 
       
   165     // handle the command.
       
   166     
       
   167     TInt count = iPlugins.Count();
       
   168     for ( TInt index = 0; index < count && !handler; ++index )
       
   169         {
       
   170         TRAPD( error,
       
   171             // Loop though until a command handler is found
       
   172             for (; index < count && !handler; ++index )
       
   173                 {
       
   174                 if ( !iPlugins[index]->IsDisabled() )
       
   175                     {
       
   176                     handler = iPlugins[index]->Plugin().CommandHandlerL( aCommand );
       
   177                     }
       
   178                 }
       
   179              );
       
   180 
       
   181         if ( error )
       
   182             {
       
   183             // Report a problem with plugin.
       
   184             }
       
   185         }
       
   186     
       
   187     TRACE_EXIT_POINT;
       
   188     return handler;
       
   189     }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CCalenCustomisationManager::GetPluginSettingsL
       
   193 // Gets custom settings from the specified plugin
       
   194 // ----------------------------------------------------------------------------
       
   195 //
       
   196 EXPORT_C void CCalenCustomisationManager::GetPluginSettingsL( TUid aPluginUid,
       
   197                                                               RPointerArray<CAknSettingItem>& aSettingArray )
       
   198     {
       
   199     TRACE_ENTRY_POINT;
       
   200 
       
   201     CCalenCustomisation* plugin = FindPluginL( aPluginUid );
       
   202     User::LeaveIfNull( plugin );
       
   203 
       
   204     TRAPD( error, plugin->GetCustomSettingsL( aSettingArray ));
       
   205     if ( error )
       
   206             {
       
   207             // Report a problem with plugin.
       
   208             }
       
   209     
       
   210     TRACE_EXIT_POINT;
       
   211     }
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // CCalenCustomisationManager::ActivePlugins
       
   215 // Returns a reference to an array of active plugins uids
       
   216 // ----------------------------------------------------------------------------
       
   217 //
       
   218 EXPORT_C const RArray<TUid>& CCalenCustomisationManager::ActivePlugins() const
       
   219     {
       
   220     TRACE_ENTRY_POINT;
       
   221     TRACE_EXIT_POINT;
       
   222 
       
   223     return iActivePlugins;
       
   224     }
       
   225 
       
   226 // ----------------------------------------------------------------------------
       
   227 // CCalenCustomisationManager::CreateActivePluginListL
       
   228 // Generates the list of active plugins
       
   229 // ----------------------------------------------------------------------------
       
   230 //
       
   231 void CCalenCustomisationManager::CreateActivePluginListL()
       
   232     {
       
   233     TRACE_ENTRY_POINT;
       
   234     
       
   235     iPluginInfo.ResetAndDestroy();
       
   236     iActivePlugins.Reset();
       
   237     iRomBasedPlugins.Reset();
       
   238     
       
   239     //Added resolver for corolla release
       
   240     // Set resolver params
       
   241     /*TLanguage lang = User::Language();
       
   242     TBuf8<40> langStr;
       
   243     langStr.Format( _L8("language(%d)"), lang );
       
   244 
       
   245     TEComResolverParams resolverParams;
       
   246     resolverParams.SetDataType( langStr );
       
   247     resolverParams.SetGenericMatch( ETrue );*/
       
   248     
       
   249     REComSession::ListImplementationsL( KCalenCustomisationInterfaceUid,/* resolverParams,*/ iPluginInfo );
       
   250     
       
   251     LoadPluginsBasedOnVariantL();
       
   252     
       
   253     TInt pluginCount = iPluginInfo.Count();
       
   254     
       
   255     for ( TInt pluginIndex(0); pluginIndex < pluginCount; ++pluginIndex )
       
   256         {
       
   257         TUid pluginUid = iPluginInfo[pluginIndex]->ImplementationUid();
       
   258         
       
   259         // Find the plugin in the list of known plugins 
       
   260         TInt position = iPluginSettingsStatus.Find( pluginUid, PluginAvailabilityFinder );
       
   261         if ( ( position == KErrNotFound ) || ( iPluginSettingsStatus[position].iEnabled ) )
       
   262             {
       
   263             // If the plugin can not be found or if it is enabled
       
   264             // add it to the list of active plugins
       
   265             iActivePlugins.AppendL( pluginUid );
       
   266             
       
   267             // If the plugin is rom-based, store its uid
       
   268             if ( iPluginInfo[pluginIndex]->RomBased() )
       
   269                 {
       
   270                 iRomBasedPlugins.AppendL( pluginUid );
       
   271                 }
       
   272             }
       
   273         }
       
   274 
       
   275     TRACE_EXIT_POINT;
       
   276     }
       
   277 
       
   278 // ----------------------------------------------------------------------------
       
   279 // CCalenCustomisationManager::GetCustomViewsL
       
   280 // GetCustomViews returns custom views info in an array for a given
       
   281 // plugin. 
       
   282 // NOTE: The contents of the array are owned by the caller - caller
       
   283 // must guarantee to call ResetAndDestroy on the array in all cases.
       
   284 // ----------------------------------------------------------------------------
       
   285 //
       
   286 EXPORT_C void CCalenCustomisationManager::GetCustomViewsL( TUid aPluginUid, 
       
   287                                                            RPointerArray<CCalenView>& aViews )
       
   288     {
       
   289     TRACE_ENTRY_POINT;
       
   290 
       
   291     CCalenCustomisation* plugin = FindPluginL( aPluginUid );
       
   292     User::LeaveIfNull( plugin );
       
   293     
       
   294     TRAPD( error, plugin->GetCustomViewsL( aViews ));
       
   295     if ( error )
       
   296         {
       
   297         // Report a problem with plugin.
       
   298         }
       
   299 
       
   300     TInt numViews = aViews.Count();
       
   301     for ( TInt index( 0 ); index < numViews; ++index )
       
   302         {
       
   303         CCalenView* customView = aViews[index];
       
   304 
       
   305         // Add to view info array
       
   306         const TUid viewId = customView->Id();
       
   307         
       
   308          // Check for duplicate view ids. 
       
   309         TInt position = iViewInfoArray.Find( viewId , 
       
   310                                      CCalenViewInfo::ViewInfoIdentifier );
       
   311                                      
       
   312         if ( position == KErrNotFound )
       
   313             {
       
   314             const TDesC& menuName = customView->LocalisedViewNameL( CCalenView::EMenuName );
       
   315             const TDesC& settingsName = customView->LocalisedViewNameL( CCalenView::ESettingsName );
       
   316             const CCalenView::TCyclePosition cyclePos = customView->CyclePosition();
       
   317 
       
   318             CCalenViewInfo* viewInfo = CCalenViewInfo::NewL( viewId,
       
   319                                                              aPluginUid, 
       
   320                                                              menuName,
       
   321                                                              settingsName,
       
   322                                                              cyclePos );
       
   323                                                              
       
   324             // Check if the view has already been hidden.
       
   325             TBool hidden = ( iHiddenViews.Find( viewId.iUid ) != KErrNotFound );
       
   326             viewInfo->Hide( hidden );                     
       
   327                                                              
       
   328             ViewInfoArray().InsertInOrderAllowRepeatsL( viewInfo, iSortOrder );
       
   329             }
       
   330          else
       
   331             {
       
   332             // A plugin with the same id already exists. ( It could be a replacement
       
   333             // view provided by a rom plugin, as currently preventing rom plugins from
       
   334             // being disabled if required is not implemented, it needs to be handled)
       
   335             delete customView;
       
   336             aViews.Remove( index );
       
   337             index--; 
       
   338             numViews--;
       
   339             
       
   340             // Report a problem with plugin.
       
   341             }
       
   342          }
       
   343 	RArray<TInt> hiddenViews;
       
   344     CleanupClosePushL( hiddenViews );
       
   345     plugin->RemoveViewsFromCycle( hiddenViews );
       
   346     TInt hiddenViewCount = hiddenViews.Count();
       
   347     if ( hiddenViewCount )
       
   348        {
       
   349        // Get the default view form the settings to check if it is going to be hidden
       
   350        // by the installed plugin
       
   351        TUid defaultView = iSetting->DefaultView();
       
   352        for ( TInt index(0); index < hiddenViewCount; ++index )
       
   353            {
       
   354            TInt hiddenViewId = hiddenViews[index];
       
   355           // iHiddenViews.InsertInOrderAllowRepeatsL( hiddenViewId );
       
   356                        
       
   357            // If this view is already on the view cycle list it needs
       
   358            // to be hidden.
       
   359            TUid hiddenViewUid = TUid::Uid( hiddenViewId );
       
   360                        
       
   361            // If the current default view is hidden, then set the newly
       
   362            // installed plugin view as default view
       
   363            if(defaultView == hiddenViewUid)
       
   364                {
       
   365                TInt position = iViewInfoArray.Find( aPluginUid, 
       
   366                                                     CCalenViewInfo::ViewPluginIdentifier );
       
   367                if(position != -1)
       
   368                    {
       
   369                    for(TInt i = position; i < iViewInfoArray.Count(); i++)
       
   370                        {
       
   371                        if((iViewInfoArray[i]->PluginUid() == aPluginUid) &&
       
   372                                (iViewInfoArray[i]->CyclePosition() != CCalenView::ENoCyclePosition))
       
   373                            {
       
   374                            iSetting->SetDefaultView(iViewInfoArray[i]->ViewUid());
       
   375                            break;
       
   376                            }
       
   377                        }
       
   378                    }
       
   379                }
       
   380            }
       
   381        }
       
   382    CleanupStack::PopAndDestroy(); // removedViews
       
   383 
       
   384     TRACE_EXIT_POINT;
       
   385     }
       
   386 
       
   387 // ----------------------------------------------------------------------------
       
   388 // CCalenCustomisationManager::SetPluginAvailabilityL
       
   389 // Enables or disables the given plugin.
       
   390 // ----------------------------------------------------------------------------
       
   391 //
       
   392 EXPORT_C void CCalenCustomisationManager::SetPluginAvailabilityL( TUid aPluginUid,
       
   393                                                                   TBool aEnabled )
       
   394     {
       
   395     TRACE_ENTRY_POINT;
       
   396     
       
   397     if ( aEnabled )
       
   398         {
       
   399         EnablePluginL( aPluginUid );
       
   400         }
       
   401     else
       
   402         {
       
   403         DisablePluginL( aPluginUid );
       
   404         }
       
   405     
       
   406     TRACE_EXIT_POINT;
       
   407     }
       
   408 
       
   409 // ----------------------------------------------------------------------------
       
   410 // CCalenCustomisationManager::DisablePluginL
       
   411 // Disables the given plugin.
       
   412 // ----------------------------------------------------------------------------
       
   413 //  
       
   414  void CCalenCustomisationManager::DisablePluginL( TUid aPluginUid )
       
   415     {
       
   416     TRACE_ENTRY_POINT;
       
   417 
       
   418     // Find the plugins
       
   419     TInt index = iPlugins.Find( aPluginUid, CPluginInfo::Identifier );
       
   420     if ( index != KErrNotFound )
       
   421         {
       
   422         CPluginInfo* pluginInfo = iPlugins[index];
       
   423         
       
   424         // Check if the plugin has not already been disabled
       
   425         if ( !( pluginInfo->IsDisabled() ) )
       
   426             {
       
   427             // Mark the plugin as being disabled
       
   428             pluginInfo->Disable( ETrue );
       
   429              
       
   430             // Remove the plugin from the active plugin list
       
   431             TInt position = iActivePlugins.Find( aPluginUid );
       
   432             ASSERT( position != KErrNotFound );
       
   433             
       
   434             iActivePlugins.Remove( position );
       
   435              
       
   436             // Does this plugin hide any views
       
   437             RArray<TInt> removedViews;
       
   438             CleanupClosePushL( removedViews );
       
   439             CCalenCustomisation& plugin = pluginInfo->Plugin();
       
   440             plugin.RemoveViewsFromCycle( removedViews );
       
   441             TInt hiddenViewsCount = removedViews.Count();
       
   442             if ( hiddenViewsCount )
       
   443                 {
       
   444                 // Need to recalculate which views have been hidden, as 
       
   445                 // more than one plugin might have hidden the same view.
       
   446                 for ( TInt index( 0 ); index < hiddenViewsCount; ++index )
       
   447                     {
       
   448                     TUid viewUid = TUid::Uid( removedViews[index] );
       
   449                     CheckHiddenViewL( viewUid, aPluginUid );
       
   450                     }
       
   451                 }
       
   452 
       
   453             // If the plugin does not offer any views, or the current
       
   454             // info or preview bar it can be deleted immediately,
       
   455             // otherwise the customisation needs to wait until it
       
   456             // is told it is safe to do so.
       
   457 
       
   458             // Does this plugin does not offer any views and the plugin
       
   459             // doesn't offer the current infobar or preview pane
       
   460             // bar it can be deleted immediately
       
   461             TInt offerViews = iViewInfoArray.Find( aPluginUid, 
       
   462                                        CCalenViewInfo::ViewPluginIdentifier );
       
   463                                               
       
   464             if ( offerViews == KErrNotFound &&
       
   465                  iInfoBarProviderUid != aPluginUid
       
   466                  && iPreviewPaneProviderUid != aPluginUid )
       
   467                 {
       
   468                 RArray<TUid> pluginArray;
       
   469                 CleanupClosePushL( pluginArray );
       
   470                 pluginArray.AppendL( aPluginUid );
       
   471                 UnloadPluginsL( pluginArray );
       
   472                 CleanupStack::PopAndDestroy(); // pluginArray
       
   473                 }
       
   474 
       
   475             // Issue notification of plugin been disabled
       
   476             iPluginsEnabledDisabled = ETrue;
       
   477             iServices.IssueNotificationL( ECalenNotifyPluginEnabledDisabled );
       
   478             CleanupStack::PopAndDestroy(); // removedViews
       
   479             }
       
   480         }
       
   481         
       
   482 
       
   483     TRACE_EXIT_POINT;
       
   484     }
       
   485 
       
   486 // ----------------------------------------------------------------------------
       
   487 // CCalenCustomisationManager::UnloadPluginsL
       
   488 // When a plugin is disabled it can not be unloaded until
       
   489 // any views etc it has provided have been deleted. This function
       
   490 // is called when it is safe to unload the plugin.
       
   491 // ----------------------------------------------------------------------------
       
   492 //
       
   493 EXPORT_C void CCalenCustomisationManager::UnloadPluginsL( const RArray<TUid>& aPlugins )
       
   494     {
       
   495     TRACE_ENTRY_POINT;
       
   496     // Check plugin isn't already enabled
       
   497     TInt count = aPlugins.Count();
       
   498     for (TInt index = 0; index < count; ++index )
       
   499         {
       
   500         TInt position = iPlugins.Find( aPlugins[index], CPluginInfo::Identifier );
       
   501         if ( position != KErrNotFound ) 
       
   502 	        {
       
   503         	if((iInfoBarProviderUid != iPlugins[position]->Uid())
       
   504         		&& (iPreviewPaneProviderUid != iPlugins[ position]->Uid()))
       
   505 	            {
       
   506 	            CPluginInfo* removedPlugin = iPlugins[ position ];
       
   507 	            iPlugins.Remove( position );
       
   508 	            delete removedPlugin;
       
   509 	            }
       
   510         	else 
       
   511 	        	{
       
   512 	        	iPlugins[position]->Disable(ETrue);
       
   513 				iDefferedUnloadPluginList.AppendL(iPlugins[position]->Uid());
       
   514 				iInfoBarProviderUid = KNullUid;
       
   515 				iPreviewPaneProviderUid = KNullUid;
       
   516 	        	}
       
   517 		   }
       
   518         }
       
   519     TRACE_EXIT_POINT;
       
   520     }
       
   521 
       
   522 // ----------------------------------------------------------------------------
       
   523 // CCalenCustomisationManager::EnablePluginL
       
   524 // Enables the given plugin. Returns KErrNotFound if
       
   525 // the plugin can't be found, KErrNone otherwise.
       
   526 // ----------------------------------------------------------------------------
       
   527 //
       
   528 void CCalenCustomisationManager::EnablePluginL( TUid aPluginUid )
       
   529     {
       
   530     TRACE_ENTRY_POINT;
       
   531     
       
   532     // Check plugin isn't already enabled
       
   533     TInt index = iPlugins.Find( aPluginUid, CPluginInfo::Identifier);
       
   534     
       
   535     if ( index == KErrNotFound )
       
   536         {
       
   537         // Load plugin
       
   538         TRAPD( error, LoadPluginL( aPluginUid ) );
       
   539         if ( error )
       
   540             {
       
   541             // report a problem loading the plugin
       
   542             
       
   543             }
       
   544             
       
   545         iActivePlugins.AppendL( aPluginUid );
       
   546     
       
   547         // Issue notification of plugin been added
       
   548         iPluginsEnabledDisabled = ETrue;
       
   549         iServices.IssueNotificationL( ECalenNotifyPluginEnabledDisabled );
       
   550         }
       
   551     
       
   552     TRACE_EXIT_POINT;
       
   553     }
       
   554 	
       
   555 	
       
   556 // ----------------------------------------------------------------------------
       
   557 // CCalenCustomisationManager::LoadPluginsBasedOnVariant
       
   558 // From MCalenNotificationHandler. Handles notifications.
       
   559 // (other items were commented in a header).
       
   560 // ----------------------------------------------------------------------------
       
   561 //
       
   562 void CCalenCustomisationManager::LoadPluginsBasedOnVariantL()
       
   563     {
       
   564     TRACE_ENTRY_POINT
       
   565     
       
   566     TLanguage lang = User::Language();
       
   567     
       
   568     // Based on the variant the plugins will be loaded
       
   569     // Eg. for 01 Euro regional plugins are not needed so all regional plugins will be removed 
       
   570     // other than non regional plugins.
       
   571     // for Chinese variant Thai and vietnamese plugins will be removed 
       
   572     // leaving chinese plugin and other non regional plugins.
       
   573     RArray<TUid> needsToBeRemoved;  
       
   574     
       
   575     switch(lang)
       
   576         {
       
   577         case ELangThai:
       
   578         case ELangEnglish_Thailand:
       
   579             needsToBeRemoved.Append(KCalenChineseImplUid);
       
   580             needsToBeRemoved.Append(KCalenVietnameseImplUid);
       
   581             break;
       
   582         case ELangTaiwanChinese:
       
   583         case ELangHongKongChinese:
       
   584         case ELangPrcChinese:
       
   585             needsToBeRemoved.Append(KCalenThaiImplUid);
       
   586             needsToBeRemoved.Append(KCalenVietnameseImplUid);
       
   587             break;
       
   588         case ELangVietnamese:
       
   589             needsToBeRemoved.Append(KCalenThaiImplUid);
       
   590             needsToBeRemoved.Append(KCalenChineseImplUid);
       
   591             break;
       
   592         default:
       
   593             needsToBeRemoved.Append(KCalenThaiImplUid);
       
   594             needsToBeRemoved.Append(KCalenChineseImplUid);
       
   595             needsToBeRemoved.Append(KCalenVietnameseImplUid);
       
   596             break;
       
   597         }
       
   598     
       
   599     if(needsToBeRemoved.Count())
       
   600         {
       
   601         for(TInt i = 0 ; i < needsToBeRemoved.Count() ; i++)
       
   602             {
       
   603             TInt index = iPluginInfo.Find(needsToBeRemoved[i],CCalenCustomisationManager::PluginInfoFinder);
       
   604             if( index != KErrNotFound )
       
   605                 {
       
   606                 CImplementationInformation* impl = iPluginInfo[index];
       
   607                 iPluginInfo.Remove(index);
       
   608                 delete impl;
       
   609                 }
       
   610             }
       
   611         }
       
   612     
       
   613     needsToBeRemoved.Close();
       
   614     
       
   615     TRACE_EXIT_POINT
       
   616     }
       
   617 
       
   618 // ----------------------------------------------------------------------------
       
   619 // CCalenCustomisationManager::PluginInfoFinder(
       
   620 // Matches an uid in pluginInfo.
       
   621 // (other items were commented in a header).
       
   622 // ----------------------------------------------------------------------------
       
   623 //
       
   624 TBool CCalenCustomisationManager::PluginInfoFinder( const TUid* aUid  , const CImplementationInformation&  aArrayItem)
       
   625     {
       
   626     TRACE_ENTRY_POINT; 
       
   627     TRACE_EXIT_POINT;
       
   628     return (*aUid  == aArrayItem.ImplementationUid() );
       
   629     }
       
   630 
       
   631 // ----------------------------------------------------------------------------
       
   632 // CCalenCustomisationManager::HandleNotificationL
       
   633 // From MCalenNotificationHandler. Handles notifications.
       
   634 // (other items were commented in a header).
       
   635 // ----------------------------------------------------------------------------
       
   636 //
       
   637 void CCalenCustomisationManager::HandleNotification(const TCalenNotification aNotification )
       
   638     {
       
   639     TRACE_ENTRY_POINT;
       
   640     
       
   641     PIM_TRAPD_HANDLE( HandleNotificationL(aNotification) );
       
   642     
       
   643     TRACE_EXIT_POINT;
       
   644     }
       
   645     
       
   646 // ----------------------------------------------------------------------------
       
   647 // CCalenCustomisationManager::HandleNotificationL
       
   648 // Handles notifications that the list of available plugins had been changed,
       
   649 // either by GS or by the ecom registry.
       
   650 // When plugins are enabled or disabled inside the calendar application, this
       
   651 // function will be called after the plugin enablement changes have already been 
       
   652 // made.
       
   653 // (other items were commented in a header).
       
   654 // ----------------------------------------------------------------------------
       
   655 //
       
   656 void CCalenCustomisationManager::HandleNotificationL(TCalenNotification aNotification)
       
   657     {
       
   658     TRACE_ENTRY_POINT;
       
   659     
       
   660      switch( aNotification )
       
   661         {
       
   662         case ECalenNotifyCheckPluginUnloading:
       
   663         	{
       
   664         	if(iDefferedUnloadPluginList.Count() > 0)
       
   665 	        	{
       
   666 	        	UnloadPluginsL(iDefferedUnloadPluginList);
       
   667 	        	}
       
   668         	}
       
   669         	break;
       
   670         case ECalenNotifySettingsChanged:
       
   671 	        {
       
   672 		    // Make sure that any plugins marked as enabled are enabled, and
       
   673 		    // any plugins marked as disabled are disabled.
       
   674 		    iPluginsEnabledDisabled = EFalse;
       
   675 		    TInt pluginCount = iPluginSettingsStatus.Count();
       
   676 		    for ( TInt pluginIndex(0); pluginIndex < pluginCount; ++pluginIndex )
       
   677 		        {
       
   678 		        TUid pluginUid = iPluginSettingsStatus[pluginIndex].iUid;
       
   679 		        TBool enabled = iPluginSettingsStatus[pluginIndex].iEnabled;
       
   680 		 
       
   681 		        SetPluginAvailabilityL( pluginUid, enabled );
       
   682 		        }
       
   683 		        
       
   684 		    if ( iPluginsEnabledDisabled )
       
   685 		        {
       
   686 		        iServices.IssueNotificationL( ECalenNotifySettingsChanged );
       
   687 		        }
       
   688 	        }
       
   689 	        break;
       
   690         case ECalenNotifyEComRegistryChanged:
       
   691             {
       
   692             CreateActivePluginListL();
       
   693             iSetting->UpdatePluginListL(*this);
       
   694             DoImmediatePluginLoadingL();
       
   695             iServices.IssueNotificationL(ECalenNotifyPluginEnabledDisabled);
       
   696             iServices.IssueNotificationL(ECalenNotifySettingsChanged );
       
   697             }
       
   698 	  default:
       
   699             break; 
       
   700         }
       
   701 
       
   702 	  TRACE_EXIT_POINT;
       
   703     }  
       
   704 
       
   705 // ----------------------------------------------------------------------------
       
   706 // CCalenCustomisationManager::PluginInfoArray
       
   707 // Returns a const reference to the plugin information array.
       
   708 // (other items were commented in a header).
       
   709 // ----------------------------------------------------------------------------
       
   710 //
       
   711 EXPORT_C const RImplInfoPtrArray& CCalenCustomisationManager::PluginInfoArray() const
       
   712     {
       
   713     TRACE_ENTRY_POINT;
       
   714     TRACE_EXIT_POINT;
       
   715     return iPluginInfo;
       
   716     }
       
   717 
       
   718 // ----------------------------------------------------------------------------
       
   719 // CCalenCustomisationManager::Views
       
   720 // Returns a const reference to the views array.
       
   721 // (other items were commented in a header).
       
   722 // ----------------------------------------------------------------------------
       
   723 //
       
   724 EXPORT_C const RPointerArray<CCalenViewInfo>& CCalenCustomisationManager::Views() const
       
   725     {
       
   726     TRACE_ENTRY_POINT;
       
   727     TRACE_EXIT_POINT;
       
   728     return iViewInfoArray;
       
   729     }
       
   730 
       
   731 // ----------------------------------------------------------------------------
       
   732 // CCalenCustomisationManager::DoImmediatePluginLoadingL
       
   733 // Examines the properties of the plugin list and
       
   734 // loads those that need to loaded on start-up
       
   735 // (other items were commented in a header).
       
   736 // ----------------------------------------------------------------------------
       
   737 //
       
   738 void CCalenCustomisationManager::DoImmediatePluginLoadingL()
       
   739     {
       
   740     TRACE_ENTRY_POINT;
       
   741 
       
   742     
       
   743     for(TInt i = 0 ; i < iPlugins.Count() ; i++)
       
   744         {
       
   745         RArray<TUid> pluginArray;
       
   746         CleanupClosePushL( pluginArray );
       
   747         pluginArray.AppendL( iPlugins[i]->Uid() );
       
   748         UnloadPluginsL( pluginArray );
       
   749         CleanupStack::PopAndDestroy(); // pluginArray
       
   750         }
       
   751     
       
   752     // Get the number plugins
       
   753     TInt pluginCount = iPluginInfo.Count();
       
   754 
       
   755     for ( TInt index( 0 ); index < pluginCount; ++index )
       
   756         {
       
   757         TUid pluginUid = iPluginInfo[index]->ImplementationUid();
       
   758         if ( iActivePlugins.Find( pluginUid ) != KErrNotFound )
       
   759             {
       
   760             TRAPD( error, LoadPluginL( pluginUid ) );
       
   761             if ( error )
       
   762                 {
       
   763                 // report a problem loading the plugin
       
   764                 
       
   765                 }
       
   766             }
       
   767         }
       
   768    
       
   769     TRACE_EXIT_POINT;
       
   770     }
       
   771 
       
   772 // ----------------------------------------------------------------------------
       
   773 // CCalenCustomisationManager::LoadPluginL
       
   774 // Loads a plugin
       
   775 // (other items were commented in a header).
       
   776 // ----------------------------------------------------------------------------
       
   777 //
       
   778 void CCalenCustomisationManager::LoadPluginL( TUid aPluginUid )
       
   779     {
       
   780     TRACE_ENTRY_POINT;
       
   781 
       
   782     // Get a new services object from global data
       
   783     MCalenServices* services = iServicesFactory.NewServicesL();
       
   784     
       
   785     // Creates the plugin and transfers ownership of the services
       
   786     // object to the plugin.
       
   787     CCalenCustomisation* plugin = 
       
   788         CCalenCustomisation::CreateImplementationL( aPluginUid, services );
       
   789     
       
   790    CleanupStack::PushL( plugin );
       
   791 
       
   792     // the plugin array takes ownership of the plugin
       
   793     AddPluginL( plugin, aPluginUid  );
       
   794     CleanupStack::Pop( plugin );
       
   795 
       
   796         
       
   797     RArray<TInt> hiddenViews;
       
   798     CleanupClosePushL( hiddenViews );
       
   799     plugin->RemoveViewsFromCycle( hiddenViews );
       
   800     TInt hiddenViewCount = hiddenViews.Count();
       
   801     if ( hiddenViewCount )
       
   802         {
       
   803         // Get the default view form the settings to check if it is going to be hidden
       
   804         // by the installed plugin
       
   805         TUid defaultView = iSetting->DefaultView();
       
   806         for ( TInt index(0); index < hiddenViewCount; ++index )
       
   807             {
       
   808             TInt hiddenViewId = hiddenViews[index];
       
   809             iHiddenViews.InsertInOrderAllowRepeatsL( hiddenViewId );
       
   810             
       
   811             // If this view is already on the view cycle list it needs
       
   812             // to be hidden.
       
   813             TUid hiddenViewUid = TUid::Uid( hiddenViewId );
       
   814             
       
   815             // If the current default view is hidden, then set the newly
       
   816             // installed plugin view as default view
       
   817             if(defaultView == hiddenViewUid)
       
   818             	iSetting->SetDefaultView(aPluginUid);
       
   819             
       
   820             TInt position = iViewInfoArray.Find( hiddenViewUid, 
       
   821                                      CCalenViewInfo::ViewInfoIdentifier );
       
   822                                      
       
   823             if ( position != KErrNotFound )
       
   824                 {
       
   825                 CCalenViewInfo* viewInfo = iViewInfoArray[position];
       
   826                 viewInfo->Hide( ETrue );
       
   827                 
       
   828                 // By hiding the view, the cycleposition order may be changed
       
   829                 // so the view info array needs to be resorted.
       
   830                 iViewInfoArray.Sort( iSortOrder );
       
   831                 }
       
   832             }
       
   833         }
       
   834     CleanupStack::PopAndDestroy(); // removedViews
       
   835 
       
   836     TRACE_EXIT_POINT;
       
   837     }
       
   838 
       
   839  // ----------------------------------------------------------------------------
       
   840 // CCalenCustomisationManager::OfferMenuPaneL
       
   841 // Offers a menupane for customisation by plugins
       
   842 // and the controller.
       
   843 // (other items were commented in a header).
       
   844 // ----------------------------------------------------------------------------
       
   845 //
       
   846 EXPORT_C void CCalenCustomisationManager::OfferMenuPaneL( TInt aResourceId,
       
   847                                                           CEikMenuPane* aMenuPane )
       
   848     {
       
   849     TRACE_ENTRY_POINT;
       
   850 
       
   851     // Offer the menu to registered plugins
       
   852     OfferMenuPaneToPluginsL( aResourceId, aMenuPane );
       
   853 
       
   854     // If the menupane is a main menu, a check needs to be made that the
       
   855     // exit and switch view commands exist
       
   856 
       
   857     // Replace the send menu if it exists
       
   858     TInt position( 0 );
       
   859     if ( aMenuPane->MenuItemExists( ECalenSend, position) )
       
   860         {
       
   861         // Delete the existing send menu option
       
   862         aMenuPane->DeleteMenuItem(ECalenSend);
       
   863 
       
   864         // Insert the calensend menu item
       
   865         iGlobalData->CalenSendL().DisplaySendMenuItemL( *aMenuPane, position );
       
   866         } 
       
   867 
       
   868     // If the menu has a view switch menu item, it is up to the 
       
   869     // customisation manager to decide if the menu should be 
       
   870     // cascading or a selection list box. 
       
   871     if ( aMenuPane->MenuItemExists( ECalenSwitchView, position) )
       
   872         {
       
   873         CEikMenuPaneItem::SData& switchItem =  aMenuPane->ItemData( ECalenSwitchView );
       
   874         if ( iActivePlugins.Count() == 0 )
       
   875             {
       
   876             // Create a cascading menu
       
   877             switchItem.iCascadeId = R_CALENDAR_CHANGE_VIEW_MENUPANE;
       
   878             }
       
   879         else
       
   880             {
       
   881             switchItem.iCascadeId = 0;
       
   882             }
       
   883         }
       
   884 
       
   885     TRACE_EXIT_POINT;
       
   886     }
       
   887     
       
   888 // ----------------------------------------------------------------------------
       
   889 // CCalenCustomisationManager::CheckHiddenViewL(
       
   890 // A check needs to be made to see if any other plugins hide the same view.
       
   891 // ----------------------------------------------------------------------------
       
   892 //
       
   893 void CCalenCustomisationManager::CheckHiddenViewL( TUid aViewUid, TUid aPluginUid )
       
   894     {
       
   895     TRACE_ENTRY_POINT;
       
   896     
       
   897     // Find the viewId in the hidden view list, and remove it
       
   898     TInt viewId = aViewUid.iUid;
       
   899     TInt position = iHiddenViews.Find( viewId );
       
   900     if ( position != KErrNotFound )
       
   901         {
       
   902         iHiddenViews.Remove( position );
       
   903         
       
   904         // Try to find the view again, in case it is hidden by another view
       
   905         position = iHiddenViews.Find( viewId );
       
   906         if ( position == KErrNotFound )
       
   907             {
       
   908             // If it can't be found in the hidden view list,
       
   909             // it can be unhidden. 
       
   910             TInt viewInfoPos = iViewInfoArray.Find( aViewUid , 
       
   911                                      CCalenViewInfo::ViewInfoIdentifier );
       
   912                                      
       
   913             if ( viewInfoPos != KErrNotFound )
       
   914                 {
       
   915                 // Unhide the view
       
   916                 CCalenViewInfo* viewInfo = iViewInfoArray[viewInfoPos];
       
   917                 viewInfo->Hide( EFalse );
       
   918                 
       
   919                 // Set hidden view as default view if the currently disabled plugin
       
   920                 // is the default view
       
   921                 TInt position = iViewInfoArray.Find( aPluginUid, 
       
   922                                                            CCalenViewInfo::ViewPluginIdentifier );
       
   923                 if(position != -1)
       
   924                   {
       
   925                   for(TInt i = position; i < iViewInfoArray.Count(); i++)
       
   926                       {
       
   927                       if((iViewInfoArray[i]->PluginUid() == aPluginUid) &&
       
   928                               iViewInfoArray[i]->ViewUid() == iSetting->DefaultView())
       
   929                           {
       
   930                           iSetting->SetDefaultView(aViewUid);
       
   931                           break;
       
   932                           }
       
   933                       }
       
   934                   }
       
   935                                 
       
   936                 // By unhiding the view, the cycleposition order may be changed
       
   937                 // so the view info array needs to be resorted.
       
   938                 iViewInfoArray.Sort( iSortOrder );
       
   939                 }
       
   940             }
       
   941         }
       
   942     TRACE_EXIT_POINT;
       
   943     }
       
   944 
       
   945 // ----------------------------------------------------------------------------
       
   946 // CCalenCustomisationManager::GetReplacePluginViewIdL
       
   947 // Returns the view ID of the plugin that hides a particular view
       
   948 // ----------------------------------------------------------------------------
       
   949 //
       
   950 EXPORT_C TUid CCalenCustomisationManager::GetReplacePluginViewIdL( TUid aHiddenViewId )
       
   951 	{
       
   952 	TRACE_ENTRY_POINT;
       
   953 	
       
   954 	RArray<TInt> removedViews;
       
   955 	CCalenCustomisation* plugin = NULL;
       
   956 	TInt i = 0;
       
   957 	for( ;i < iActivePlugins.Count(); i++)
       
   958 	{
       
   959         plugin = FindPluginL(iActivePlugins[i]);
       
   960 		plugin->RemoveViewsFromCycle(removedViews);
       
   961 		if(removedViews.Count())
       
   962 		{
       
   963 			TInt position = removedViews.Find(aHiddenViewId.iUid);
       
   964 			if(position != KErrNotFound)
       
   965 			    break;
       
   966 			else
       
   967 				continue;
       
   968 		    }
       
   969 		else
       
   970 		    {
       
   971 			continue;
       
   972 		    }	
       
   973 	    }
       
   974 	removedViews.Reset();
       
   975 	
       
   976 	// Get all the views provided by the plugin
       
   977 	//plugin->GetCustomViewsL()
       
   978 	TInt position = iViewInfoArray.Find( iActivePlugins[i], 
       
   979 	                                       CCalenViewInfo::ViewPluginIdentifier );
       
   980 	while((position < iViewInfoArray.Count()) && ((iViewInfoArray[position]->CyclePosition() == CCalenView::ENoCyclePosition) ||
       
   981 	        (iActivePlugins[i] != (iViewInfoArray[position]->PluginUid()))))
       
   982 	    {
       
   983 	    // go to the next view position
       
   984 	    position++;
       
   985 	    }
       
   986     TRACE_EXIT_POINT;   
       
   987 
       
   988     return (iViewInfoArray[position]->ViewUid());
       
   989 	}
       
   990 
       
   991 // ----------------------------------------------------------------------------
       
   992 // CCalenCustomisationManager::GetReplacePluginViewIdL
       
   993 // Returns the hidden views list 
       
   994 // ----------------------------------------------------------------------------
       
   995 //
       
   996 EXPORT_C void CCalenCustomisationManager::GetHiddenViewIdL( TUid aPluginUid, RArray<TInt>& aHiddenViews )
       
   997 	{
       
   998 	TRACE_ENTRY_POINT;
       
   999 	
       
  1000 	// Get the plugin instance
       
  1001 	CCalenCustomisation* plugin = FindPluginL(aPluginUid);
       
  1002 	
       
  1003 	plugin->RemoveViewsFromCycle(aHiddenViews);
       
  1004 	
       
  1005 	TRACE_EXIT_POINT;	
       
  1006 	}
       
  1007 
       
  1008 // ----------------------------------------------------------------------------
       
  1009 // CCalenCustomisationManager::CustomPreviewPaneL
       
  1010 // Returns the preview pane
       
  1011 // (other items were commented in a header).
       
  1012 // ----------------------------------------------------------------------------
       
  1013 EXPORT_C MCalenPreview* CCalenCustomisationManager::CustomPreviewPaneL( TRect& aRect )
       
  1014 	{
       
  1015 	MCalenPreview* previewPane = NULL;
       
  1016    
       
  1017    
       
  1018     // Loop though all the command handlers, within two interlinked
       
  1019     // for loops. If PreviewPaneL leaves for one plugin, a plugin
       
  1020     // error message will be displayed and the loop will continue with
       
  1021     // the next command handler. If none of the plugins leave, there will
       
  1022     // be only one TRAP used.
       
  1023     TInt count = iPlugins.Count();
       
  1024     for ( TInt index = 0; index < count && !previewPane; ++index )
       
  1025         {
       
  1026         TRAPD( error,
       
  1027                 {
       
  1028                  // Loop though until an infobar is found
       
  1029                 for (; index < count && !previewPane; ++index )
       
  1030                     {
       
  1031                     if ( !iPlugins[index]->IsDisabled() )
       
  1032                         {
       
  1033                         previewPane = iPlugins[index]->Plugin().CustomPreviewPaneL( aRect );
       
  1034                         }
       
  1035                     }
       
  1036                 }
       
  1037              );
       
  1038         if ( error )
       
  1039             {
       
  1040             // Report a problem with plugin.
       
  1041             }
       
  1042         }
       
  1043     
       
  1044     TRACE_EXIT_POINT;
       
  1045     return previewPane;
       
  1046 	}
       
  1047 // ----------------------------------------------------------------------------
       
  1048 // CCalenCustomisationManager::PreviewPane
       
  1049 // Returns the preview pane
       
  1050 // (other items were commented in a header).
       
  1051 // ----------------------------------------------------------------------------
       
  1052 EXPORT_C CCoeControl* CCalenCustomisationManager::PreviewPane(   TRect& aRect  )
       
  1053     {
       
  1054     TRACE_ENTRY_POINT;
       
  1055 	
       
  1056     iInfoBarProviderUid = TUid::Uid(0);;		
       
  1057     iPreviewPaneProviderUid = TUid::Uid(0);
       
  1058     
       
  1059     CCoeControl* previewPane = NULL;
       
  1060    
       
  1061     // Loop though all the command handlers, within two interlinked
       
  1062     // for loops. If PreviewPaneL leaves for one plugin, a plugin
       
  1063     // error message will be displayed and the loop will continue with
       
  1064     // the next command handler. If none of the plugins leave, there will
       
  1065     // be only one TRAP used.
       
  1066     TInt count = iPlugins.Count();
       
  1067     for ( TInt index = 0; index < count && !previewPane; ++index )
       
  1068         {
       
  1069         TRAPD( error,
       
  1070             // Loop though until an infobar is found
       
  1071             for (; index < count && !previewPane; ++index )
       
  1072                 {
       
  1073                 
       
  1074                 if ( !iPlugins[index]->IsDisabled() )
       
  1075                     {
       
  1076                     previewPane = iPlugins[index]->Plugin().PreviewPaneL( aRect );
       
  1077                     if(previewPane)
       
  1078 						{
       
  1079                     	iPreviewPaneProviderUid = iPlugins[index]->Uid();
       
  1080 						}
       
  1081                     }
       
  1082                 
       
  1083                 }
       
  1084              );
       
  1085 
       
  1086         if ( error )
       
  1087             {
       
  1088             // Report a problem with plugin.
       
  1089             }
       
  1090         }
       
  1091     
       
  1092     TRACE_EXIT_POINT;
       
  1093     return previewPane;
       
  1094     }
       
  1095 
       
  1096 // ----------------------------------------------------------------------------
       
  1097 // CCalenCustomisationManager::Infobar
       
  1098 // Returns the infobar.
       
  1099 // (other items were commented in a header).
       
  1100 // ----------------------------------------------------------------------------
       
  1101 EXPORT_C CCoeControl* CCalenCustomisationManager::Infobar(const  TRect& aRect )
       
  1102     {
       
  1103     TRACE_ENTRY_POINT;
       
  1104 
       
  1105     iInfoBarProviderUid = TUid::Uid(0);
       
  1106     iPreviewPaneProviderUid = TUid::Uid(0);
       
  1107     
       
  1108     CCoeControl* infoBar = NULL;
       
  1109     // Loop though all the command handlers, within two interlinked
       
  1110     // for loops. If GetInfoBarL leaves for one plugin, a plugin
       
  1111     // error message will be displayed and the loop will continue with
       
  1112     // the next command handler. If none of the plugins leave, there will
       
  1113     // be only one TRAP used.
       
  1114     TInt count = iPlugins.Count();
       
  1115     for ( TInt index = 0; index < count && !infoBar; ++index )
       
  1116         {
       
  1117         TRAPD( error,
       
  1118             // Loop though until an infobar is found
       
  1119             for (; index < count && !infoBar; ++index )
       
  1120                 {
       
  1121                 if ( !iPlugins[index]->IsDisabled() )
       
  1122                     {
       
  1123                     infoBar = iPlugins[index]->Plugin().InfobarL( aRect  );
       
  1124                     iInfoBarProviderUid = iPlugins[index]->Uid();
       
  1125                     }
       
  1126                 }
       
  1127              );
       
  1128 
       
  1129         if ( error )
       
  1130             {
       
  1131             // Report a problem with plugin.
       
  1132             }
       
  1133         }
       
  1134         
       
  1135     TRACE_EXIT_POINT;   
       
  1136     return infoBar;
       
  1137     }
       
  1138     
       
  1139 // ----------------------------------------------------------------------------
       
  1140 // CCalenCustomisationManager::Infobar
       
  1141 // Returns the infobar.
       
  1142 // (other items were commented in a header).
       
  1143 // ----------------------------------------------------------------------------
       
  1144 EXPORT_C const TDesC& CCalenCustomisationManager::Infobar()
       
  1145     {
       
  1146     TRACE_ENTRY_POINT;
       
  1147 
       
  1148     iInfoBarProviderUid = TUid::Uid(0);
       
  1149     iPreviewPaneProviderUid = TUid::Uid(0);
       
  1150     
       
  1151     iInfoBarStr.Set(KNullDesC);
       
  1152     // Loop though all the command handlers, within two interlinked
       
  1153     // for loops. If GetInfoBarL leaves for one plugin, a plugin
       
  1154     // error message will be displayed and the loop will continue with
       
  1155     // the next command handler. If none of the plugins leave, there will
       
  1156     // be only one TRAP used.
       
  1157     TBool infoBarFound = EFalse;
       
  1158     TInt count = iPlugins.Count();
       
  1159     for ( TInt index = 0; index < count && !infoBarFound; ++index )
       
  1160         {
       
  1161         TRAPD( error,
       
  1162             // Loop though until an infobar is found
       
  1163             for (; index < count && !infoBarFound; ++index )
       
  1164                 {
       
  1165                 if ( !iPlugins[index]->IsDisabled() )
       
  1166                     {
       
  1167                     iInfoBarStr.Set( iPlugins[index]->Plugin().InfobarL() );
       
  1168                     if(iInfoBarStr.Length())
       
  1169                         {
       
  1170                         infoBarFound = ETrue;
       
  1171                         }
       
  1172                     iInfoBarProviderUid = iPlugins[index]->Uid();
       
  1173                     }
       
  1174                 }
       
  1175              );
       
  1176 
       
  1177         if ( error )
       
  1178             {
       
  1179             // Report a problem with plugin.
       
  1180             }
       
  1181         }
       
  1182         
       
  1183     TRACE_EXIT_POINT;   
       
  1184     return iInfoBarStr;
       
  1185     }
       
  1186     
       
  1187 // ----------------------------------------------------------------------------
       
  1188 // CCalenCustomisationManager::HiddenView
       
  1189 // Return ETrue if a view has been hidden by a plugin
       
  1190 // (other items were commented in a header).
       
  1191 // ----------------------------------------------------------------------------
       
  1192 //         
       
  1193 EXPORT_C TBool CCalenCustomisationManager::HiddenView( TUid aHiddenView) const
       
  1194     {
       
  1195     TRACE_ENTRY_POINT;
       
  1196     TRACE_EXIT_POINT;
       
  1197     return ( iHiddenViews.Find( aHiddenView.iUid ) != KErrNotFound );
       
  1198     }
       
  1199     
       
  1200     
       
  1201 // ----------------------------------------------------------------------------
       
  1202 // CCalenCustomisationManager::RomBased(
       
  1203 // Return ETrue if a view has been provided by a rom-based plugin
       
  1204 // (other items were commented in a header).
       
  1205 // ----------------------------------------------------------------------------
       
  1206 //  
       
  1207 EXPORT_C TBool CCalenCustomisationManager::IsViewRomBased( TUid aViewUid ) const
       
  1208     {
       
  1209     TRACE_ENTRY_POINT;
       
  1210     
       
  1211     TBool isRomBased = EFalse;
       
  1212     
       
  1213     TInt viewInfoPos = iViewInfoArray.Find( aViewUid , 
       
  1214                                      CCalenViewInfo::ViewInfoIdentifier );
       
  1215     if ( viewInfoPos != KErrNotFound )
       
  1216         {
       
  1217         TUid plugUid = iViewInfoArray[viewInfoPos]->PluginUid();
       
  1218         TInt position = iRomBasedPlugins.Find( plugUid );
       
  1219         if ( position != KErrNotFound )
       
  1220             {
       
  1221             isRomBased = ETrue;
       
  1222             }
       
  1223         }
       
  1224     
       
  1225     TRACE_EXIT_POINT;
       
  1226     return isRomBased;
       
  1227     }
       
  1228 
       
  1229 // ----------------------------------------------------------------------------
       
  1230 // CCalenCustomisationManager::CanBeEnabledDisabled(
       
  1231 // Return ETrue if plugins can be enabled/disabled from settings
       
  1232 // (other items were commented in a header).
       
  1233 // ----------------------------------------------------------------------------
       
  1234 //
       
  1235 EXPORT_C TBool CCalenCustomisationManager::CanBeEnabledDisabledL(TUid aPluginUid)
       
  1236     {
       
  1237     TRACE_ENTRY_POINT;
       
  1238     TBool enabledDisabled = EFalse;
       
  1239     
       
  1240     CCalenCustomisation* plugin = FindPluginL(aPluginUid);
       
  1241     if(plugin)
       
  1242 		{
       
  1243         enabledDisabled = plugin->CanBeEnabledDisabled();
       
  1244 		}
       
  1245     
       
  1246     TRACE_EXIT_POINT;
       
  1247     return enabledDisabled;
       
  1248     }
       
  1249 
       
  1250 // ----------------------------------------------------------------------------
       
  1251 // CCalenCustomisationManager::OfferMenuPaneL
       
  1252 // Offers a menupane to all interested plugins
       
  1253 // (other items were commented in a header).
       
  1254 // ----------------------------------------------------------------------------
       
  1255 //
       
  1256 void CCalenCustomisationManager::OfferMenuPaneToPluginsL( TInt aResourceId,
       
  1257                                                           CEikMenuPane* aMenuPane )
       
  1258     {
       
  1259     TRACE_ENTRY_POINT;
       
  1260 
       
  1261     // Get the number of command handlers
       
  1262  //   TInt count = iCommandHandlers.Count();
       
  1263     const TInt count = iPlugins.Count();
       
  1264 
       
  1265     // Loop though all the command handlers, within two interlinked
       
  1266     // for loops. If customiseMenuPane leaves for one plugin, a plugin
       
  1267     // error message will be displayed and the loop will continue with
       
  1268     // the next command handler. If none of the plugins leave, there will
       
  1269     // be only one TRAP used.
       
  1270     for ( TInt index = 0; index < count; ++index )
       
  1271         {
       
  1272         TRAPD( error,
       
  1273             for (; index < count; ++index )
       
  1274                 {
       
  1275                 iPlugins[index]->Plugin().CustomiseMenuPaneL( aResourceId,
       
  1276                                                              aMenuPane );
       
  1277                                                              
       
  1278                 // The commands added should be checked to see that
       
  1279                 // they match the expected command range for the plugin
       
  1280                 }
       
  1281              );
       
  1282          
       
  1283         if ( error )
       
  1284             {
       
  1285             // Report a problem with plugin.
       
  1286             }
       
  1287         }
       
  1288 
       
  1289     TRACE_EXIT_POINT;
       
  1290     }
       
  1291 
       
  1292 // ----------------------------------------------------------------------------
       
  1293 // CCalenCustomisationManager::FindPluginL
       
  1294 // Finds a plugin and returns a plugin with a given uid, returns NULL
       
  1295 // if the uid can not be found.
       
  1296 // (other items were commented in a header).
       
  1297 // ----------------------------------------------------------------------------
       
  1298 //
       
  1299 CCalenCustomisation* CCalenCustomisationManager::FindPluginL( TUid aUid )
       
  1300     {
       
  1301     TRACE_ENTRY_POINT;
       
  1302 
       
  1303     TInt index = iPlugins.Find( aUid, CPluginInfo::Identifier );
       
  1304     
       
  1305     CCalenCustomisation* plugin = NULL;
       
  1306     if ( index != KErrNotFound )
       
  1307         {
       
  1308         plugin = &( iPlugins[index]->Plugin() );
       
  1309         }
       
  1310 
       
  1311     TRACE_EXIT_POINT; 
       
  1312     return plugin;
       
  1313     }
       
  1314 
       
  1315 // ----------------------------------------------------------------------------
       
  1316 // CCalenCustomisationManager::CPluginInfo::CPluginInfo(
       
  1317 // C++ constructor
       
  1318 // (other items were commented in a header).
       
  1319 // ----------------------------------------------------------------------------
       
  1320 //
       
  1321 CCalenCustomisationManager::CPluginInfo::CPluginInfo( 
       
  1322                                     CCalenCustomisation* aPlugin,
       
  1323                                     TUid aUid )
       
  1324     : iPlugin( aPlugin ),
       
  1325       iUid( aUid )
       
  1326     {
       
  1327     TRACE_ENTRY_POINT;
       
  1328     TRACE_EXIT_POINT;
       
  1329     }
       
  1330 
       
  1331 // ----------------------------------------------------------------------------
       
  1332 // CCalenCustomisationManager::CPluginInfo::~CPluginInfo(
       
  1333 // C++ destructor
       
  1334 // (other items were commented in a header).
       
  1335 // ----------------------------------------------------------------------------
       
  1336 //
       
  1337 CCalenCustomisationManager::CPluginInfo::~CPluginInfo() 
       
  1338     {
       
  1339     TRACE_ENTRY_POINT;
       
  1340 
       
  1341     delete iPlugin;
       
  1342 
       
  1343     TRACE_EXIT_POINT;
       
  1344     }
       
  1345     
       
  1346 // ----------------------------------------------------------------------------
       
  1347 // CCalenCustomisationManager::CPluginInfo::Plugin
       
  1348 // returns a reference to the plugin
       
  1349 // (other items were commented in a header).
       
  1350 // ----------------------------------------------------------------------------
       
  1351 //
       
  1352 CCalenCustomisation& CCalenCustomisationManager::CPluginInfo::Plugin()
       
  1353     {
       
  1354     TRACE_ENTRY_POINT;
       
  1355     TRACE_EXIT_POINT;
       
  1356 
       
  1357     return *iPlugin;
       
  1358     }
       
  1359 
       
  1360 // ----------------------------------------------------------------------------
       
  1361 // CCalenCustomisationManager::CPluginInfo::Uid
       
  1362 // returns the plugin uid
       
  1363 // (other items were commented in a header).
       
  1364 // ----------------------------------------------------------------------------
       
  1365 // 
       
  1366 TUid CCalenCustomisationManager::CPluginInfo::Uid() const 
       
  1367     {
       
  1368     TRACE_ENTRY_POINT; 
       
  1369     TRACE_EXIT_POINT;
       
  1370 
       
  1371     return iUid;
       
  1372     }
       
  1373    
       
  1374 // ----------------------------------------------------------------------------
       
  1375 // CCalenCustomisationManager::CPluginInfo::Disable
       
  1376 // Marks the plugin as being disabled
       
  1377 // (other items were commented in a header).
       
  1378 // ----------------------------------------------------------------------------
       
  1379 //  
       
  1380 void CCalenCustomisationManager::CPluginInfo::Disable( TBool aDisable)
       
  1381     {
       
  1382     TRACE_ENTRY_POINT;
       
  1383     
       
  1384     iDisabled = aDisable;
       
  1385      
       
  1386     TRACE_EXIT_POINT;
       
  1387     }
       
  1388     
       
  1389 // ----------------------------------------------------------------------------
       
  1390 // CCalenCustomisationManager::CPluginInfo::IsDisabled
       
  1391 // Returns if the plugin has been marked as being disabled
       
  1392 // (other items were commented in a header).
       
  1393 // ----------------------------------------------------------------------------
       
  1394 //  
       
  1395 TBool CCalenCustomisationManager::CPluginInfo::IsDisabled()
       
  1396     {
       
  1397     TRACE_ENTRY_POINT;
       
  1398     
       
  1399     return iDisabled;
       
  1400      
       
  1401     TRACE_EXIT_POINT;
       
  1402     }
       
  1403 
       
  1404 // ----------------------------------------------------------------------------
       
  1405 // CCalenCustomisationManager::AddPluginL
       
  1406 // Adds a plugin to the array of plugins
       
  1407 // (other items were commented in a header).
       
  1408 // ----------------------------------------------------------------------------
       
  1409 //           
       
  1410 void CCalenCustomisationManager::AddPluginL( CCalenCustomisation* aPlugin,
       
  1411                                              TUid aUid ) 
       
  1412     {
       
  1413     TRACE_ENTRY_POINT;
       
  1414 
       
  1415     CPluginInfo* newPlugin = new ( ELeave ) CPluginInfo( aPlugin, aUid);
       
  1416     CleanupStack::PushL( newPlugin );
       
  1417     iPlugins.AppendL( newPlugin );
       
  1418     CleanupStack::Pop( newPlugin );
       
  1419 
       
  1420     TRACE_EXIT_POINT;
       
  1421     }
       
  1422 
       
  1423 // ----------------------------------------------------------------------------
       
  1424 // CCalenCustomisationManager::CPluginInfo::Identifier(
       
  1425 // Matches an uid and a plugin uid. Used by FindPluginL to
       
  1426 // find a plugin with a given uid. 
       
  1427 // (other items were commented in a header).
       
  1428 // ----------------------------------------------------------------------------
       
  1429 //
       
  1430 TBool CCalenCustomisationManager::CPluginInfo::Identifier( const TUid* aUid,
       
  1431                                                            const CPluginInfo& aArray )
       
  1432     {
       
  1433     TRACE_ENTRY_POINT; 
       
  1434     TRACE_EXIT_POINT;
       
  1435 
       
  1436     return ( *aUid == aArray.Uid() ); 
       
  1437     }
       
  1438 
       
  1439 // ----------------------------------------------------------------------------
       
  1440 // CCalenCustomisationManager::ViewInfoArray
       
  1441 // returns a reference to the view info array.
       
  1442 // (other items were commented in a header).
       
  1443 // ----------------------------------------------------------------------------      
       
  1444 //
       
  1445 RPointerArray<CCalenViewInfo>& CCalenCustomisationManager::ViewInfoArray()
       
  1446     {
       
  1447     TRACE_ENTRY_POINT;
       
  1448 
       
  1449     TRACE_EXIT_POINT;
       
  1450     return iViewInfoArray;
       
  1451     }    
       
  1452     
       
  1453 // ----------------------------------------------------------------------------
       
  1454 // CCalenCustomisationManager::PluginAvailabilityFinder
       
  1455 // Matches an uid and a plugin uid. Used by when finding the disabled plugins
       
  1456 // (other items were commented in a header).
       
  1457 // ----------------------------------------------------------------------------
       
  1458 //  
       
  1459 TBool CCalenCustomisationManager::PluginAvailabilityFinder( const TUid* aUid, 
       
  1460                                  const TCalenPluginAvailability& aArrayItem )
       
  1461     {
       
  1462     TRACE_ENTRY_POINT; 
       
  1463     TRACE_EXIT_POINT;
       
  1464     
       
  1465     return ( *aUid == aArrayItem.iUid); 
       
  1466     }    
       
  1467 
       
  1468 // ----------------------------------------------------------------------------
       
  1469 // CCalenCustomisationManager::DoPluginLoadingL
       
  1470 // Load all plugins 
       
  1471 // ----------------------------------------------------------------------------
       
  1472 //
       
  1473 EXPORT_C void CCalenCustomisationManager::DoPluginLoadingL()
       
  1474     {
       
  1475     TRACE_ENTRY_POINT;
       
  1476     // Reset and destroy the contents of the owned arrays
       
  1477     iPlugins.ResetAndDestroy();
       
  1478 
       
  1479     iPluginInfo.ResetAndDestroy();
       
  1480 
       
  1481     iActivePlugins.Reset();
       
  1482 
       
  1483     iHiddenViews.Reset();
       
  1484     iDefferedUnloadPluginList.Reset();
       
  1485     // create active plugin list
       
  1486     CreateActivePluginListL();
       
  1487     
       
  1488     DoImmediatePluginLoadingL();
       
  1489     iSetting->LoadL();
       
  1490     iSetting->UpdatePluginListL(*this);
       
  1491     
       
  1492     TRACE_EXIT_POINT;
       
  1493     }
       
  1494 
       
  1495 // ----------------------------------------------------------------------------
       
  1496 // CCalenCustomisationManager::DisableAllPluginsL
       
  1497 // Disable all plugins 
       
  1498 // ----------------------------------------------------------------------------
       
  1499 //
       
  1500 EXPORT_C void CCalenCustomisationManager::DisableAllPluginsL()
       
  1501     {
       
  1502     TRACE_ENTRY_POINT;
       
  1503     
       
  1504     TInt pluginCount = iPluginInfo.Count();
       
  1505     for(TInt index = 0;index<pluginCount;index++)
       
  1506         {
       
  1507         TUid pluginUid = iPluginInfo[index]->ImplementationUid();
       
  1508         if(iActivePlugins.Find(pluginUid)!=KErrNotFound)
       
  1509             {
       
  1510             DisablePluginOnFakeExitL(pluginUid);
       
  1511             }
       
  1512         }
       
  1513     
       
  1514     TRACE_EXIT_POINT;
       
  1515     }
       
  1516 
       
  1517 // ----------------------------------------------------------------------------
       
  1518 // CCalenCustomisationManager::DisablePluginOnFakeExitL
       
  1519 // Disable plugin on fake exit
       
  1520 // ----------------------------------------------------------------------------
       
  1521 //
       
  1522 void CCalenCustomisationManager::DisablePluginOnFakeExitL(TUid aPluginUid)
       
  1523     {
       
  1524     TRACE_ENTRY_POINT;
       
  1525     
       
  1526     TInt index = iPlugins.Find( aPluginUid, CPluginInfo::Identifier );
       
  1527     if ( index != KErrNotFound )
       
  1528         {
       
  1529         CPluginInfo* pluginInfo = iPlugins[index];
       
  1530     
       
  1531         // Remove the plugin from the active plugin list
       
  1532         TInt position = iActivePlugins.Find( aPluginUid );
       
  1533         ASSERT( position != KErrNotFound );
       
  1534     
       
  1535         if(iActivePlugins.Count())
       
  1536             {
       
  1537             iActivePlugins.Remove( position );            
       
  1538             }
       
  1539 
       
  1540         // Does this plugin hide any views
       
  1541         RArray<TInt> removedViews;
       
  1542         CleanupClosePushL( removedViews );
       
  1543         CCalenCustomisation& plugin = pluginInfo->Plugin();
       
  1544         plugin.RemoveViewsFromCycle( removedViews );
       
  1545         TInt hiddenViewsCount = removedViews.Count();
       
  1546         if ( hiddenViewsCount )
       
  1547             {
       
  1548             // Need to recalculate which views have been hidden, as 
       
  1549             // more than one plugin might have hidden the same view.
       
  1550             for ( TInt index( 0 ); index < hiddenViewsCount; ++index )
       
  1551                 {
       
  1552                 TUid viewUid = TUid::Uid( removedViews[index] );
       
  1553                 CheckHiddenViewL( viewUid, aPluginUid );
       
  1554                 }
       
  1555             }
       
  1556     
       
  1557         // If the plugin does not offer any views, or the current
       
  1558         // info or preview bar it can be deleted immediately,
       
  1559         // otherwise the customisation needs to wait until it
       
  1560         // is told it is safe to do so.
       
  1561     
       
  1562         // Does this plugin does not offer any views and the plugin
       
  1563         // doesn't offer the current infobar or preview pane
       
  1564         // bar it can be deleted immediately
       
  1565         TInt offerViews = iViewInfoArray.Find( aPluginUid, 
       
  1566                                    CCalenViewInfo::ViewPluginIdentifier );
       
  1567                                       
       
  1568         if ( offerViews == KErrNotFound &&
       
  1569              iInfoBarProviderUid != aPluginUid
       
  1570              && iPreviewPaneProviderUid != aPluginUid )
       
  1571             {
       
  1572             RArray<TUid> pluginArray;
       
  1573             CleanupClosePushL( pluginArray );
       
  1574             pluginArray.AppendL( aPluginUid );
       
  1575             UnloadPluginsL( pluginArray );
       
  1576             CleanupStack::PopAndDestroy(); // pluginArray
       
  1577             }
       
  1578     
       
  1579         // Issue notification of plugin been disabled
       
  1580         iPluginsEnabledDisabled = ETrue;
       
  1581         iServices.IssueNotificationL( ECalenNotifyPluginEnabledDisabled );
       
  1582         CleanupStack::PopAndDestroy(); // removedViews
       
  1583         }
       
  1584     TRACE_EXIT_POINT;
       
  1585     }
       
  1586 
       
  1587 // End of File
       
  1588