meetingrequest/mrbcplugin/src/cmrbcplugin.cpp
branchRCL_3
changeset 16 4ce476e64c59
child 24 b5fbb9b25d57
equal deleted inserted replaced
13:0396474f30f5 16:4ce476e64c59
       
     1 /*
       
     2 * Copyright (c) 2009-2009 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:  Implements RECAL customisation api
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDES
       
    19 #include "cmrbcplugin.h"
       
    20 #include "cmrbcpluginentryloader.h"
       
    21 #include "cmrbcpluginresourcereader.h"
       
    22 #include "cmrbceventplugin.h"
       
    23 #include "esmrhelper.h"
       
    24 #include "esmrdef.h"
       
    25 #include "esmrinternaluid.h"
       
    26 
       
    27 #include <calendar.rsg>
       
    28 #include <calenservices.h>
       
    29 #include <eikmenup.h>
       
    30 #include <bautils.h>
       
    31 #include <ecom/ecom.h>
       
    32 #include <meetingrequestuids.hrh>
       
    33 #include <ct/rcpointerarray.h>
       
    34 #include <data_caging_path_literals.hrh>
       
    35 #include <caleninterimutils2.h>
       
    36 #include <calencommands.hrh>
       
    37 #include <featdiscovery.h>
       
    38 #include <bldvariant.hrh>
       
    39 
       
    40 #include "emailtrace.h"
       
    41 
       
    42 namespace { // codescanner::namespace
       
    43 
       
    44 #ifdef _DEBUG
       
    45 
       
    46 // Panic literal
       
    47 _LIT( KMRBCPlugin, "MRBCPlugin" );
       
    48 
       
    49 enum TMRBCPluginPanic
       
    50     {
       
    51     ENoBCPluginsFound // No MRUi MR Viewer Impl found
       
    52     };
       
    53 
       
    54 void Panic( TMRBCPluginPanic aPanic )
       
    55     {
       
    56     User::Panic( KMRBCPlugin, aPanic );
       
    57     }
       
    58 
       
    59 #endif // _DEBUG
       
    60 
       
    61 TBCPluginEventType EventTypeL(
       
    62         MCalenServices& aServices,
       
    63         CCalEntry& aEntry )
       
    64     {
       
    65     TBCPluginEventType eventType( EMRTypeNone );
       
    66 
       
    67     CCalenInterimUtils2& utils = aServices.InterimUtilsL();
       
    68     if ( utils.IsMeetingRequestL(aEntry) )
       
    69         {
       
    70         eventType = EMRTypeMeetingRequest;
       
    71         }
       
    72     else
       
    73         {
       
    74         switch( aEntry.EntryTypeL() )
       
    75             {
       
    76             case CCalEntry::EAppt:
       
    77                 eventType = EMRTypeMeeting;
       
    78                 break;
       
    79 
       
    80             case CCalEntry::ETodo:
       
    81                 eventType = EMRTypeToDo;
       
    82                 break;
       
    83 
       
    84             case CCalEntry::EEvent:
       
    85                 eventType = EMRTypeMemo;
       
    86                 break;
       
    87 
       
    88             case CCalEntry::EAnniv:
       
    89                 eventType = EMRTypeAnniversary;
       
    90                 break;
       
    91             }
       
    92         }
       
    93 
       
    94     return eventType;
       
    95     }
       
    96 
       
    97 /**
       
    98  * Checks if features for handling commands are enabled
       
    99  * @param aCommand command to check
       
   100  * @return ETrue if feature is enabled for handling the given command
       
   101  */
       
   102 TBool IsCommandHandlerEnabledL( TInt aCommand )
       
   103     {
       
   104     FUNC_LOG;
       
   105 
       
   106     TBool enabled( ETrue );
       
   107 
       
   108     switch ( aCommand )
       
   109         {
       
   110         case ECalenNewMeetingRequest:
       
   111             {
       
   112             if ( !CFeatureDiscovery::IsFeatureSupportedL(
       
   113                     TUid::Uid( KFeatureIdFfCalMeetingRequestUi ) ) )
       
   114                 {
       
   115                 // KFeatureIdFfCalMeetingRequestUi is not supported.
       
   116                 // Disable ECalenNewMeetingRequest command handling.
       
   117                 enabled = EFalse;
       
   118                 }
       
   119             break;
       
   120             }
       
   121 
       
   122         case ECalenEventView:
       
   123             {
       
   124             break;
       
   125             }
       
   126 
       
   127         case ECalenNewMeeting:
       
   128         case ECalenNewTodo:
       
   129         case ECalenNewAnniv:
       
   130         case ECalenNewDayNote:
       
   131             {
       
   132             if ( !CFeatureDiscovery::IsFeatureSupportedL(
       
   133                     TUid::Uid( KFeatureIdFfEnhancedCalendarEventUi ) ) )
       
   134                 {
       
   135                 // KFeatureIdFfEnhancedCalendarEventUi is not supported.
       
   136                 // Disable enhanced event editors.
       
   137                 enabled = EFalse;
       
   138                 }
       
   139             break;
       
   140             }
       
   141 
       
   142         case ECalenNewMeetingTimeSpan:
       
   143             {
       
   144             if ( !CFeatureDiscovery::IsFeatureSupportedL(
       
   145                     TUid::Uid( KFeatureIdFfCalMeetingRequestUi ) )
       
   146                  && !CFeatureDiscovery::IsFeatureSupportedL(
       
   147                          TUid::Uid( KFeatureIdFfEnhancedCalendarEventUi ) ) )
       
   148                 {
       
   149                 enabled = EFalse;
       
   150                 }
       
   151             break;
       
   152             }
       
   153             
       
   154         default:
       
   155             {
       
   156             enabled = EFalse;
       
   157             break;
       
   158             }
       
   159         }
       
   160 
       
   161     return enabled;
       
   162     }
       
   163 
       
   164 /**
       
   165  * Checks is feature for handling a command is enabled
       
   166  * @param aCommand the command to handle
       
   167  * @param aType the event type
       
   168  * @return ETrue if command handling is enabled
       
   169  */
       
   170 TBool IsCommandSupportedForEntryTypeL(
       
   171         TInt aCommand,
       
   172         TBCPluginEventType aType )
       
   173     {
       
   174     FUNC_LOG;
       
   175 
       
   176     TBool supported = ETrue;
       
   177 
       
   178     if ( aCommand == ECalenEventView )
       
   179         {
       
   180         // Check that corresponding viewer feature is enabled
       
   181         switch ( aType )
       
   182             {
       
   183             case EMRTypeMeetingRequest:
       
   184                 {
       
   185                 if ( !CFeatureDiscovery::IsFeatureSupportedL(
       
   186                         TUid::Uid( KFeatureIdFfCalMeetingRequestUi ) ) )
       
   187                     {
       
   188                     // Meeting request viewer is not supported
       
   189                     supported = EFalse;
       
   190                     }
       
   191                 break;
       
   192                 }
       
   193 
       
   194             case EMRTypeMeeting:
       
   195             case EMRTypeMemo:
       
   196             case EMRTypeAnniversary:
       
   197             case EMRTypeToDo:
       
   198                 {
       
   199                 if ( !CFeatureDiscovery::IsFeatureSupportedL(
       
   200                         TUid::Uid( KFeatureIdFfEnhancedCalendarEventUi ) ) )
       
   201                     {
       
   202                     // Enhanced event viewers are not supported
       
   203                     supported = EFalse;
       
   204                     }
       
   205                 break;
       
   206                 }
       
   207             default:
       
   208                 {
       
   209                 supported = EFalse;
       
   210                 break;
       
   211                 }
       
   212 
       
   213             }
       
   214         }
       
   215 
       
   216     return supported;
       
   217     }
       
   218 
       
   219 } // namespace
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CMRBCPlugin::CMRBCPlugin
       
   223 // C++ constructor for this class
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 CMRBCPlugin::CMRBCPlugin( MCalenServices* aServices )
       
   227 :   iServices( aServices )
       
   228     {
       
   229     FUNC_LOG;
       
   230     // Do nothing
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CMRBCPlugin::~CMRBCPlugin
       
   235 // Destructor for this class
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 CMRBCPlugin::~CMRBCPlugin()
       
   239     {
       
   240     FUNC_LOG;
       
   241 
       
   242     if ( iServices )
       
   243         {
       
   244         iServices->Release();
       
   245         }
       
   246 
       
   247     iPluginResources.ResetAndDestroy();
       
   248     delete iEntryLoader;
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CMRBCPlugin::NewL
       
   253 // Static constructor for this class
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 CMRBCPlugin* CMRBCPlugin::NewL(
       
   257         MCalenServices* aServices )
       
   258     {
       
   259     FUNC_LOG;
       
   260 
       
   261     CMRBCPlugin* self = new ( ELeave ) CMRBCPlugin( aServices );
       
   262     CleanupStack::PushL( self );
       
   263     self->ConstructL();
       
   264     CleanupStack::Pop( self );
       
   265     return self;
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CMRBCPlugin::ConstructL
       
   270 // 2nd phase constructor for this class.
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 void CMRBCPlugin::ConstructL()
       
   274     {
       
   275     FUNC_LOG;
       
   276 
       
   277     RCPointerArray<CImplementationInformation> bcPlugins;
       
   278     CleanupClosePushL( bcPlugins );
       
   279 
       
   280     REComSession::ListImplementationsL(
       
   281             TUid::Uid(KMRBCEventPluginInterfaceUID),
       
   282             bcPlugins );
       
   283 
       
   284     TInt pluginCount(  bcPlugins.Count() );
       
   285     __ASSERT_DEBUG( pluginCount , Panic( ENoBCPluginsFound) );
       
   286 
       
   287     if ( !pluginCount )
       
   288         {
       
   289         ERROR( KErrNotFound, "No BC Plugins found" );
       
   290         User::Leave( KErrNotFound );
       
   291         }
       
   292 
       
   293     for ( TInt i(0); i < pluginCount; ++i )
       
   294         {
       
   295         HBufC* resourceFileName =
       
   296                     HBufC::NewLC( bcPlugins[i]->OpaqueData().Length() );
       
   297         resourceFileName->Des().Copy( bcPlugins[i]->OpaqueData() );
       
   298 
       
   299         CMRBCPluginResourceReader* pluginResource =
       
   300                 CMRBCPluginResourceReader::NewL( *iServices );
       
   301         CleanupStack::PushL( pluginResource );
       
   302 
       
   303         TFileName resource;
       
   304         TInt err = ESMRHelper::LocateResourceFile(
       
   305                         *resourceFileName,
       
   306                         KDC_RESOURCE_FILES_DIR,
       
   307                         resource,
       
   308                         NULL );
       
   309 
       
   310         User::LeaveIfError( err );
       
   311 
       
   312         pluginResource->ReadFromResourceFileL(
       
   313                 bcPlugins[i]->ImplementationUid(),
       
   314                 resource );
       
   315 
       
   316         User::LeaveIfError(
       
   317                 iPluginResources.Append( pluginResource ) );
       
   318 
       
   319         CleanupStack::Pop( pluginResource );
       
   320         CleanupStack::PopAndDestroy( resourceFileName );
       
   321         }
       
   322 
       
   323     // bcPlugins
       
   324     CleanupStack::PopAndDestroy();  // codescanner::cleanup
       
   325 
       
   326     iEntryLoader = CMRBCPluginEntryLoader::NewL( *iServices );
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CMRBCPlugin::GetCustomViewsL
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 void CMRBCPlugin::GetCustomViewsL(
       
   334         RPointerArray<CCalenView>& /*aCustomViewArray*/ )
       
   335     {
       
   336     FUNC_LOG;
       
   337 
       
   338     // Do nothing
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CMRBCPlugin::GetCustomSettingsL
       
   343 // No implementation needed
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CMRBCPlugin::GetCustomSettingsL( RPointerArray<CAknSettingItem>& /*aCustomSettingArray*/ )
       
   347     {
       
   348     FUNC_LOG;
       
   349 
       
   350     // Do nothing
       
   351     }
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CMRBCPlugin::InfobarL
       
   355 // No implementation needed
       
   356 // -----------------------------------------------------------------------------
       
   357 //
       
   358 CCoeControl* CMRBCPlugin::InfobarL( const TRect& /*aRect*/ )
       
   359     {
       
   360     FUNC_LOG;
       
   361 
       
   362     // Do nothing
       
   363     return NULL;
       
   364     }
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 // CMRBCPlugin::InfobarL
       
   368 // No implementation needed
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 const TDesC& CMRBCPlugin::InfobarL()
       
   372     {
       
   373     FUNC_LOG;
       
   374 
       
   375     return KNullDesC;
       
   376     }
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // CMRBCPlugin::CustomPreviewPaneL
       
   380 // No implementation needed
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 MCalenPreview* CMRBCPlugin::CustomPreviewPaneL( TRect& /*aRect*/ )
       
   384     {
       
   385     FUNC_LOG;
       
   386 
       
   387     // Do nothing
       
   388     return NULL;
       
   389     }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CMRBCPlugin::PreviewPaneL
       
   393 // No implementation needed
       
   394 // -----------------------------------------------------------------------------
       
   395 //
       
   396 CCoeControl* CMRBCPlugin::PreviewPaneL( TRect& /*aRect*/ )
       
   397     {
       
   398     FUNC_LOG;
       
   399 
       
   400     // Do nothing
       
   401     return NULL;
       
   402     }
       
   403 
       
   404 // -----------------------------------------------------------------------------
       
   405 // CMRBCPlugin::CommandHandlerL
       
   406 // Decides what command handler is returned
       
   407 // -----------------------------------------------------------------------------
       
   408 //
       
   409 MCalenCommandHandler* CMRBCPlugin::CommandHandlerL(
       
   410         TInt aCommand )
       
   411     {
       
   412     FUNC_LOG;
       
   413 
       
   414     MCalenCommandHandler* cmdHandler = NULL;
       
   415 
       
   416     if ( IsCommandHandlerEnabledL( aCommand ) )
       
   417         {
       
   418         cmdHandler = ResolveCommandHandlerL( aCommand );
       
   419         }
       
   420 
       
   421     return cmdHandler;
       
   422     }
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CMRBCPlugin::RemoveViewsFromCycle
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 void CMRBCPlugin::RemoveViewsFromCycle( RArray<TInt>& /*aViews*/ )
       
   429     {
       
   430     FUNC_LOG;
       
   431 
       
   432     // Do nothing
       
   433     }
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // CMRBCPlugin::CustomiseMenuPaneL
       
   437 // No implementation needed
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 TBool CMRBCPlugin::CustomiseMenuPaneL( TInt /*aResourceId*/, CEikMenuPane* /*aMenuPane*/ )
       
   441     {
       
   442     FUNC_LOG;
       
   443 
       
   444     return EFalse;
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CMRBCPlugin::CanBeEnabledDisabled
       
   449 // No implementation needed
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 TBool CMRBCPlugin::CanBeEnabledDisabled()
       
   453     {
       
   454     FUNC_LOG;
       
   455 
       
   456     return EFalse;
       
   457     }
       
   458 
       
   459 // -----------------------------------------------------------------------------
       
   460 // CMRBCPlugin::CalenCustomisationExtensionL
       
   461 // No implementation needed
       
   462 // -----------------------------------------------------------------------------
       
   463 //
       
   464 TAny* CMRBCPlugin::CalenCustomisationExtensionL( TUid /*aExtensionUid*/ )
       
   465     {
       
   466     FUNC_LOG;
       
   467 
       
   468     return NULL;
       
   469     }
       
   470 
       
   471 // -----------------------------------------------------------------------------
       
   472 // CMRBCPlugin::ResolveCommandHandlerL
       
   473 // -----------------------------------------------------------------------------
       
   474 //
       
   475 MCalenCommandHandler* CMRBCPlugin::ResolveCommandHandlerL( TInt aCommand )
       
   476     {
       
   477     MCalenCommandHandler* cmdHandler = NULL;
       
   478 
       
   479     //Open meetingview instead of mr while can't resolve phone owner.
       
   480     //This situation command ECalenOpenMeetingView will be received.
       
   481     if( EMRLaunchMeetingViewer == aCommand )
       
   482         {
       
   483         CMRBCEventPlugin* eventPlugin = PluginByUidL(
       
   484                 TUid::Uid( KMRBCMREventPluginImplementationUID ) );
       
   485         
       
   486         if ( eventPlugin )
       
   487             {
       
   488             cmdHandler = eventPlugin->CommandHandler();
       
   489             }
       
   490         }
       
   491     else
       
   492         {
       
   493         TInt pluginCount( iPluginResources.Count() );
       
   494         for ( TInt i(0); i < pluginCount && !cmdHandler; ++i )
       
   495             {
       
   496             TMRBCPluginCommand pluginCommand;
       
   497     
       
   498             TInt err = iPluginResources[i]->Command( aCommand, pluginCommand );
       
   499             if ( KErrNone == err )
       
   500                 {
       
   501                 // Command was found from the plugin
       
   502                 if ( pluginCommand.CheckEntryType() )
       
   503                     {
       
   504                     iEntryLoader->UpdateEntryFromDatabaseL();
       
   505     
       
   506                     TBCPluginEventType eventType(
       
   507                             EventTypeL( *iServices, iEntryLoader->Entry() ) );
       
   508     
       
   509                     if ( iPluginResources[i]->SupportsType( eventType)
       
   510                          && IsCommandSupportedForEntryTypeL( aCommand, eventType ) )
       
   511                         {
       
   512                         cmdHandler = iPluginResources[i]->PluginL().CommandHandler();
       
   513                         }
       
   514                     }
       
   515                 else
       
   516                     {
       
   517                     cmdHandler = iPluginResources[i]->PluginL().CommandHandler();
       
   518                     }
       
   519                 }
       
   520             }
       
   521         }
       
   522     return cmdHandler;
       
   523     }
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // CMRBCPlugin::PluginByUid
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 CMRBCEventPlugin* CMRBCPlugin::PluginByUidL( TUid aUid )
       
   530     {
       
   531     CMRBCEventPlugin* plugin = NULL;
       
   532     
       
   533     for ( TInt i = 0; i < iPluginResources.Count() && !plugin; ++i )
       
   534         {
       
   535         if ( iPluginResources[ i ]->PluginImplUid() == aUid )
       
   536             {
       
   537             plugin = &( iPluginResources[ i ]->PluginL() );
       
   538             }
       
   539         }
       
   540     
       
   541     return plugin;
       
   542     }
       
   543 
       
   544 // End of file