meetingrequest/mrpolicy/src/cesmrpolicyextensionmanager.cpp
branchRCL_3
changeset 33 da5135c61bad
parent 32 a3a1ae9acec6
child 34 cd2816114bd1
equal deleted inserted replaced
32:a3a1ae9acec6 33:da5135c61bad
     1 /*
       
     2 * Copyright (c) 2008-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:  ESMR policy extension manager implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrpolicyextensionmanager.h"
       
    20 
       
    21 #include "esmrinternaluid.h"
       
    22 
       
    23 // System includes
       
    24 #include <bautils.h>    // BaflUtils
       
    25 #include <coemain.h>    // CCoeEnv
       
    26 #include <ecom/implementationinformation.h> // RImplInfoPtrArray
       
    27 #include <ecom/ecom.h>  // REComSession
       
    28 
       
    29 /// Unnamed namespace for local definitions
       
    30 namespace {
       
    31 const TInt KESMRExtensionResourceFileOffset ( 2 );
       
    32 
       
    33 /**
       
    34  * Custom cleanup function.
       
    35  * @param aObj  Object to clean.
       
    36  */
       
    37 void CleanupResetAndDestroy( TAny* aObj )
       
    38     {
       
    39     if ( aObj )
       
    40         {
       
    41         static_cast<RImplInfoPtrArray*>( aObj )->ResetAndDestroy();
       
    42         }
       
    43     }
       
    44 
       
    45 } // namespace
       
    46 
       
    47 // ======== MEMBER FUNCTIONS ========
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CESMRExtensionResourceFile::CESMRExtensionResourceFile
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CESMRExtensionResourceFile::CESMRExtensionResourceFile( RFs& aFs )
       
    54 : iFsSession( aFs )
       
    55     {
       
    56     FUNC_LOG;
       
    57     // do nothing
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CESMRExtensionResourceFile::NewL
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CESMRExtensionResourceFile*
       
    65 CESMRExtensionResourceFile::NewL( const TDesC& aPath, RFs& aFs )
       
    66     {
       
    67     CESMRExtensionResourceFile* self =
       
    68         new (ELeave) CESMRExtensionResourceFile( aFs );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL( aPath );
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CESMRExtensionResourceFile::~CESMRExtensionResourceFile
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CESMRExtensionResourceFile::~CESMRExtensionResourceFile()
       
    80     {
       
    81     FUNC_LOG;
       
    82     iResFile.Close();
       
    83     // Don't close the fssession, we have only reference to CCoeEnv's RFs
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CESMRExtensionResourceFile::ConstructL
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CESMRExtensionResourceFile::ConstructL( const TDesC& aPath )
       
    91     {
       
    92     FUNC_LOG;
       
    93     TFindFile findFile( iFsSession );
       
    94     TInt error = findFile.FindByDir( aPath, KNullDesC() );
       
    95     if ( error == KErrNone )
       
    96         {
       
    97         TFileName fileName;
       
    98         fileName.Append( findFile.File() );
       
    99         // Solve the FullPath
       
   100         BaflUtils::NearestLanguageFile(iFsSession, fileName);
       
   101         iResFile.OpenL(iFsSession, fileName);
       
   102         iResFile.ConfirmSignatureL();
       
   103 
       
   104         // Extension resource should be always the first resource in the
       
   105         // rss file.
       
   106         iResId = iResFile.Offset() + KESMRExtensionResourceFileOffset;
       
   107         }
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CESMRExtensionResourceFile::ResId
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 TInt CESMRExtensionResourceFile::ResId() const
       
   115     {
       
   116     FUNC_LOG;
       
   117     return iResId;
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CESMRExtensionResourceFile::ResFile
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 RResourceFile& CESMRExtensionResourceFile::ResFile()
       
   125     {
       
   126     FUNC_LOG;
       
   127     return iResFile;
       
   128     }
       
   129 
       
   130 
       
   131 
       
   132 ///////////////////////////////////////////////////////////////////////////////
       
   133 // ======== MEMBER FUNCTIONS ========
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // CESMRPolicyExtensionManager::CESMRPolicyExtensionManager
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 CESMRPolicyExtensionManager::CESMRPolicyExtensionManager( CCoeEnv& aCoeEnv )
       
   140 : iCoeEnv( aCoeEnv )
       
   141     {
       
   142     FUNC_LOG;
       
   143     // do nothing
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CESMRPolicyExtensionManager::NewL
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 CESMRPolicyExtensionManager* CESMRPolicyExtensionManager::NewL(
       
   151         CCoeEnv& aCoeEnv )
       
   152     {
       
   153     FUNC_LOG;
       
   154     CESMRPolicyExtensionManager* self =
       
   155         new (ELeave) CESMRPolicyExtensionManager( aCoeEnv );
       
   156     CleanupStack::PushL( self );
       
   157     self->ConstructL();
       
   158     CleanupStack::Pop( self );
       
   159     return self;
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CESMRPolicyExtensionManager::~CESMRPolicyExtensionManager
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 CESMRPolicyExtensionManager::~CESMRPolicyExtensionManager()
       
   167     {
       
   168     FUNC_LOG;
       
   169     iResourceFiles.ResetAndDestroy();
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CESMRPolicyExtensionManager::ConstructL
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CESMRPolicyExtensionManager::ConstructL()
       
   177     {
       
   178     FUNC_LOG;
       
   179     // do nothing
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CESMRPolicyExtensionManager::ReadResourcesFromExtensionsL
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CESMRPolicyExtensionManager::ReadResourcesFromExtensionsL()
       
   187     {
       
   188     FUNC_LOG;
       
   189     RImplInfoPtrArray implementations;
       
   190     REComSession::ListImplementationsL(TUid::Uid(
       
   191             KESMRSchedulingviewInterfaceUid), implementations);
       
   192     CleanupStack::PushL(TCleanupItem(
       
   193             CleanupResetAndDestroy, &implementations));
       
   194 
       
   195     // loop through UI extensions in reverse order
       
   196     const TInt count = implementations.Count();
       
   197     for (TInt i = count - 1; i >= 0; --i)
       
   198         {
       
   199         CImplementationInformation* implInfo = implementations[i];
       
   200         CleanupStack::PushL(implInfo);
       
   201         implementations.Remove(i);
       
   202 
       
   203         TFileName resourceFileName;
       
   204         resourceFileName.Copy(implInfo->OpaqueData());
       
   205         if ( resourceFileName != KNullDesC() && resourceFileName.Length() != 0 )
       
   206             {
       
   207             CESMRExtensionResourceFile* resFile = NULL;
       
   208             TRAPD( err, resFile = CESMRExtensionResourceFile::NewL(
       
   209                     resourceFileName, iCoeEnv.FsSession() ) );
       
   210             if ( err == KErrNone  && resFile )
       
   211                 {
       
   212                 iResourceFiles.AppendL( resFile );
       
   213                 }
       
   214             }
       
   215         CleanupStack::PopAndDestroy( implInfo );
       
   216         }
       
   217     CleanupStack::PopAndDestroy(); // implementations
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // CESMRPolicyExtensionManager::ReadBufferL
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 HBufC8* CESMRPolicyExtensionManager::ReadBufferL( TInt aResourceId )
       
   225     {
       
   226     FUNC_LOG;
       
   227     HBufC8* buffer = NULL;
       
   228     TInt count( iResourceFiles.Count() );
       
   229     for ( TInt i = 0; i < count; ++i )
       
   230         {
       
   231         CESMRExtensionResourceFile* resFile = iResourceFiles[i];
       
   232         if ( resFile->ResId() == aResourceId )
       
   233             {
       
   234             buffer = resFile->ResFile().AllocReadL(aResourceId);
       
   235             }
       
   236         }
       
   237 
       
   238     return buffer;
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // CESMRPolicyExtensionManager::ExtensionResourceFile
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 CESMRExtensionResourceFile* CESMRPolicyExtensionManager::ExtensionResourceFile(
       
   246         TInt aResourceId )
       
   247     {
       
   248     FUNC_LOG;
       
   249     CESMRExtensionResourceFile* file = NULL;
       
   250     TInt count( iResourceFiles.Count() );
       
   251     for ( TInt i = 0; i < count; ++i )
       
   252         {
       
   253         CESMRExtensionResourceFile* resFile = iResourceFiles[i];
       
   254         if ( resFile->ResId() == aResourceId )
       
   255             {
       
   256             file = resFile;
       
   257             break;
       
   258             }
       
   259         }
       
   260 
       
   261     return file;
       
   262     }
       
   263 
       
   264 //EOF
       
   265