meetingrequest/mrutils/src/cesmrutils.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-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 MRUtils implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //INCLUDE FILES
       
    20 #include "emailtrace.h"
       
    21 #include "cesmrutils.h"
       
    22 #include "cesmrcaldbmgr.h"
       
    23 
       
    24 // From ESMRSERVICES
       
    25 #include <esmrpolicies.rsg>
       
    26 //<cmail>
       
    27 #include "cesmrpolicymanager.h"
       
    28 #include "tesmrscenariodata.h"
       
    29 #include "cesmrpolicy.h"
       
    30 //</cmail>
       
    31 
       
    32 #include "cesmrentryprocessor.h"
       
    33 #include "mesmrmeetingrequestentry.h"
       
    34 #include "cesmrtaskfactory.h"
       
    35 #include "mesmrtask.h"
       
    36 #include "cesmrtaskextensionimpl.h"
       
    37 #include "esmrinternaluid.h"
       
    38 #include "esmrhelper.h"
       
    39 
       
    40 // From System
       
    41 #include <coemain.h>
       
    42 #include <calentry.h>
       
    43 #include <calinstance.h>
       
    44 #include <calsession.h>
       
    45 #include <calcommon.h>
       
    46 #include <caluser.h>
       
    47 #include <cmrmailboxutils.h>
       
    48 #include <msvapi.h>
       
    49 #include <msvstd.h>
       
    50 #include <data_caging_path_literals.hrh>
       
    51 
       
    52 // CONSTANTS
       
    53 /// Unnamed namespace for local definitions
       
    54 namespace {
       
    55 
       
    56 _LIT( KESMRPolicyResourceFile, "esmrpolicies.rsc" );
       
    57 
       
    58 #ifdef _DEBUG
       
    59 
       
    60 // Definition for MR UTILS panic text
       
    61 _LIT(KESMRUtilsPanicTxt, "ESMRUtils" );
       
    62 
       
    63 // MR VIEWER ctrl panic codes
       
    64 enum TESMRUtilsPanicCode
       
    65     {
       
    66     EESMRUtilsEntryProcessorNull = 0,   // Entry processon is NULL
       
    67     EESMRUtilsInvalidEntry       = 1,   // Invalid calendar entry,
       
    68     EESMRUtilsNULLCoeEnv         = 2    // CCoeEnv is NULL
       
    69     };
       
    70 
       
    71 void Panic(TESMRUtilsPanicCode aPanicCode)
       
    72     {
       
    73     User::Panic( KESMRUtilsPanicTxt, aPanicCode );
       
    74     }
       
    75 
       
    76 #endif
       
    77 
       
    78 }  // namespace
       
    79 
       
    80 // ======== MEMBER FUNCTIONS ========
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // CESMRUtils::CESMRUtils
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 CESMRUtils::CESMRUtils(
       
    87         MMRUtilsObserver& aObserver )
       
    88 :   iObserver( aObserver )
       
    89     {
       
    90     FUNC_LOG;
       
    91     }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CESMRUtils::~CESMRUtils
       
    95 // ----------------------------------------------------------------------------
       
    96 //
       
    97 EXPORT_C CESMRUtils::~CESMRUtils()
       
    98     {
       
    99     FUNC_LOG;
       
   100     delete iCalDBMgr;
       
   101     delete iPolicyManager;
       
   102     delete iEntryProcessor;
       
   103     delete iMRMailboxUtils;
       
   104     delete iTaskFactory;
       
   105     delete iTaskExtension;
       
   106     }
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // CESMRUtils::NewL
       
   110 // ----------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C CESMRUtils* CESMRUtils::NewL(
       
   113         MMRUtilsObserver& aObserver )
       
   114     {
       
   115     FUNC_LOG;
       
   116     CESMRUtils* self = new ( ELeave ) CESMRUtils( aObserver );
       
   117     CleanupStack::PushL( self );
       
   118     self->ConstructL();
       
   119     CleanupStack::Pop();
       
   120     return self;
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------
       
   124 // CESMRUtils::ConstructL
       
   125 // ----------------------------------------------------------------------------
       
   126 //
       
   127 void CESMRUtils::ConstructL()
       
   128     {
       
   129     FUNC_LOG;
       
   130     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   131     __ASSERT_DEBUG( coeEnv, Panic(EESMRUtilsNULLCoeEnv) );
       
   132 
       
   133     TFileName mruiPolicyResource;
       
   134     User::LeaveIfError(
       
   135             ESMRHelper::LocateResourceFile(
       
   136                     KESMRPolicyResourceFile,
       
   137                     KDC_RESOURCE_FILES_DIR,
       
   138                     mruiPolicyResource,
       
   139                     &coeEnv->FsSession() ) );
       
   140 
       
   141     iPolicyManager = CESMRPolicyManager::NewL();
       
   142     iPolicyManager->ReadPolicyFromResourceL(
       
   143             mruiPolicyResource,
       
   144             R_ESMR_POLICIES );
       
   145     }
       
   146 
       
   147 // ----------------------------------------------------------------------------
       
   148 // CESMRUtils::DeleteWithUiL
       
   149 // ----------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C TInt CESMRUtils::DeleteWithUiL(
       
   152     const CCalEntry& aEntry,
       
   153     TMsvId /*aMailbox*/ )
       
   154     {
       
   155     FUNC_LOG;
       
   156     RPointerArray<CCalEntry> entries;
       
   157     CleanupClosePushL( entries );
       
   158     User::LeaveIfError( entries.Append( &aEntry ) );
       
   159 
       
   160     CESMREntryProcessor* processor =
       
   161             CESMREntryProcessor::NewL(
       
   162                         *iMRMailboxUtils,
       
   163                         *iCalDBMgr );
       
   164 
       
   165     CleanupStack::PushL( processor );
       
   166 
       
   167     processor->ProcessL( &entries );
       
   168 
       
   169     MESMRMeetingRequestEntry& mrEntry = processor->ESMREntryL();
       
   170     if ( mrEntry.IsRecurrentEventL() )
       
   171         {
       
   172         mrEntry.SetModifyingRuleL(
       
   173                 MESMRMeetingRequestEntry::EESMRAllInSeries );
       
   174         }
       
   175 
       
   176     mrEntry.MarkMeetingCancelledL();
       
   177 
       
   178     iTaskExtension->DeleteAndSendMRL(
       
   179             EESMRCmdDeleteMR,
       
   180             mrEntry );
       
   181 
       
   182     CleanupStack::PopAndDestroy( processor );
       
   183     CleanupStack::PopAndDestroy();  //entries
       
   184 
       
   185     return KErrNone;
       
   186     }
       
   187 
       
   188 // ----------------------------------------------------------------------------
       
   189 // CESMRUtils::DeleteWithUiL
       
   190 // ----------------------------------------------------------------------------
       
   191 //
       
   192 EXPORT_C TInt CESMRUtils::DeleteWithUiL(
       
   193     CCalInstance* aInstance,
       
   194     TMsvId /*aMailbox*/ )
       
   195     {
       
   196     FUNC_LOG;
       
   197     CESMREntryProcessor* processor =
       
   198             CESMREntryProcessor::NewL(
       
   199                         *iMRMailboxUtils,
       
   200                         *iCalDBMgr );
       
   201 
       
   202     CleanupStack::PushL( processor );
       
   203 
       
   204     processor->ProcessL( *aInstance );
       
   205 
       
   206     MESMRMeetingRequestEntry& mrEntry = processor->ESMREntryL();
       
   207     mrEntry.SetModifyingRuleL(
       
   208             MESMRMeetingRequestEntry::EESMRThisOnly );
       
   209 
       
   210     mrEntry.MarkMeetingCancelledL();
       
   211 
       
   212     iTaskExtension->DeleteAndSendMRL(
       
   213                 EESMRCmdDeleteMR,
       
   214                 mrEntry );
       
   215 
       
   216     // prosessor and aInstance
       
   217     CleanupStack::PopAndDestroy( processor );
       
   218 
       
   219     // aInstance is not added to CleanupStack, because calendar
       
   220     // already has it.
       
   221     delete aInstance;
       
   222     return KErrNone;
       
   223     }
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // CESMRUtils::SendWithUiL
       
   227 // ----------------------------------------------------------------------------
       
   228 //
       
   229 EXPORT_C void CESMRUtils::SendWithUiL(
       
   230     const CCalEntry& aEntry ,
       
   231     TMsvId /*aMailbox*/ )
       
   232     {
       
   233     FUNC_LOG;
       
   234     RPointerArray<CCalEntry> entries;
       
   235     CleanupClosePushL( entries );
       
   236     User::LeaveIfError( entries.Append( &aEntry ) );
       
   237 
       
   238     CESMREntryProcessor* processor =
       
   239             CESMREntryProcessor::NewL(
       
   240                         *iMRMailboxUtils,
       
   241                         *iCalDBMgr );
       
   242 
       
   243     CleanupStack::PushL( processor );
       
   244 
       
   245     processor->ProcessL( &entries );
       
   246 
       
   247     MESMRMeetingRequestEntry& mrEntry = processor->ESMREntryL();
       
   248     
       
   249     if ( mrEntry.IsRecurrentEventL() )
       
   250             {
       
   251             mrEntry.SetModifyingRuleL(
       
   252                     MESMRMeetingRequestEntry::EESMRAllInSeries );
       
   253             }
       
   254        
       
   255     iTaskExtension->ForwardMRAsEmailL(
       
   256     			EESMRCmdForwardAsMail,
       
   257                 mrEntry );
       
   258 
       
   259     CleanupStack::PopAndDestroy( processor );
       
   260     CleanupStack::PopAndDestroy( &entries );
       
   261     }
       
   262 // ----------------------------------------------------------------------------
       
   263 // CESMRUtils::ExtensionL
       
   264 // ----------------------------------------------------------------------------
       
   265 //
       
   266 EXPORT_C TAny* CESMRUtils::ExtensionL( TUid aExtensionUid )
       
   267     {
       
   268     FUNC_LOG;
       
   269     TAny* extension = NULL;
       
   270 
       
   271     switch ( aExtensionUid.iUid )
       
   272         {
       
   273         case KESMRPolicyMgrUid:
       
   274             extension = static_cast<TAny*>(iPolicyManager);
       
   275             break;
       
   276         case KESMRMREntryProcessorUid:
       
   277             extension = static_cast<TAny*>(iEntryProcessor);
       
   278             break;
       
   279         case KESMRTaskExtensionUid:
       
   280             extension = static_cast<TAny*>(iTaskExtension);
       
   281             break;
       
   282         default:
       
   283             extension = NULL;
       
   284             break;
       
   285         }
       
   286     return extension;
       
   287     }
       
   288 
       
   289 // ----------------------------------------------------------------------------
       
   290 // CESMRUtils::SessionSetupL
       
   291 // This template method is called as a part of the ECom plugin construction.
       
   292 // This replaces much of the ordinary ConstructL() functionality, a template
       
   293 // method is easier for transmitting parameters.
       
   294 // ----------------------------------------------------------------------------
       
   295 //
       
   296 EXPORT_C void CESMRUtils::SessionSetupL(
       
   297     CCalSession& aCalSession,
       
   298     CMsvSession* aMsvSession )
       
   299     {
       
   300     FUNC_LOG;
       
   301     // Asynchronous initialization of CESMRServicesCalDbMgr:
       
   302     iCalDBMgr = CESMRCalDbMgr::NewL( aCalSession,
       
   303                                      *this );
       
   304 
       
   305     iMRMailboxUtils = CMRMailboxUtils::NewL( aMsvSession );
       
   306 
       
   307     iTaskFactory = CESMRTaskFactory::NewL( *iCalDBMgr, *iMRMailboxUtils );
       
   308 
       
   309     iEntryProcessor = CESMREntryProcessor::NewL(
       
   310                         *iMRMailboxUtils,
       
   311                         *iCalDBMgr );
       
   312 
       
   313     iTaskExtension =
       
   314         CESMRTaskExtenstionImpl::NewL(
       
   315             *iCalDBMgr,
       
   316             *iMRMailboxUtils,
       
   317             *iPolicyManager,
       
   318             *iEntryProcessor,
       
   319             *iTaskFactory );
       
   320     }
       
   321 
       
   322 // ----------------------------------------------------------------------------
       
   323 // CESMRUtils::HandleCalEngStatus
       
   324 // ----------------------------------------------------------------------------
       
   325 //
       
   326 void CESMRUtils::HandleCalEngStatus( TMRUtilsCalEngStatus aStatus )
       
   327     {
       
   328     FUNC_LOG;
       
   329     iCalEngStatus = aStatus;
       
   330     iObserver.HandleCalEngStatus( iCalEngStatus );
       
   331     }
       
   332 
       
   333 // ----------------------------------------------------------------------------
       
   334 // CESMRUtils::HandleOperation
       
   335 // ----------------------------------------------------------------------------
       
   336 //
       
   337 void CESMRUtils::HandleOperation(
       
   338         TInt /*aType*/,
       
   339         TInt /*aPercentageCompleted*/,
       
   340         TInt /*aStatus*/ )
       
   341     {
       
   342     FUNC_LOG;
       
   343     // Do nothing
       
   344     }
       
   345 
       
   346 // End of file
       
   347