meetingrequest/mrtasks/mrtaskplugin/src/cesmrstoremrtask.cpp
branchRCL_3
changeset 12 4ce476e64c59
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     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:  Implementation for ESMR base task
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrstoremrtask.h"
       
    20 
       
    21 #include <calentry.h>
       
    22 #include <calinstance.h>
       
    23 //<cmail>
       
    24 #include "mesmrutilstombsext.h"
       
    25 //</cmail>
       
    26 #include "cesmrcaldbmgr.h"
       
    27 #include "mesmrmeetingrequestentry.h"
       
    28 
       
    29 namespace { // codescanner::namespace
       
    30 
       
    31 #ifdef _DEBUG
       
    32 
       
    33 // Literal for panics
       
    34 _LIT( KESMRStoreMR, "ESMRStoreMR" );
       
    35 
       
    36 // Panic codes
       
    37 enum TESMRStoreMRPanic
       
    38     {
       
    39     EESMRStoreMRNotMeetingRequest // Entry is not meeting request
       
    40     };
       
    41 
       
    42 // ======== LOCAL FUNCTIONS ========
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // Panic wrapper method
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void Panic( TESMRStoreMRPanic aPanic )
       
    49     {
       
    50     User::Panic( KESMRStoreMR, aPanic );
       
    51     }
       
    52 
       
    53 #endif // _DEBUG
       
    54 
       
    55 }//namespace
       
    56 
       
    57 // ======== MEMBER FUNCTIONS ========
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CESMRStoreMRTask::CESMRStoreMRTask
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CESMRStoreMRTask::CESMRStoreMRTask(
       
    64         MESMRCalDbMgr& aCalDbMgr,
       
    65         MESMRMeetingRequestEntry& aEntry,
       
    66         CMRMailboxUtils& aMRMailboxUtils )
       
    67 :   CESMRTaskBase( aCalDbMgr, aEntry, aMRMailboxUtils )
       
    68     {
       
    69     FUNC_LOG;
       
    70     //do nothing
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CESMRStoreMRTask::~CESMRStoreMRTask
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CESMRStoreMRTask::~CESMRStoreMRTask()
       
    78     {
       
    79     FUNC_LOG;
       
    80     //do nothing
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CESMRStoreMRTask::NewL
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CESMRStoreMRTask* CESMRStoreMRTask::NewL(
       
    88         MESMRCalDbMgr& aCalDbMgr,
       
    89         MESMRMeetingRequestEntry& aEntry,
       
    90         CMRMailboxUtils& aMRMailboxUtils )
       
    91     {
       
    92     FUNC_LOG;
       
    93 
       
    94     CESMRStoreMRTask* self =
       
    95         new (ELeave) CESMRStoreMRTask(
       
    96             aCalDbMgr,
       
    97             aEntry,
       
    98             aMRMailboxUtils );
       
    99 
       
   100     CleanupStack::PushL(self);
       
   101     self->ConstructL();
       
   102     CleanupStack::Pop(self);
       
   103 
       
   104 
       
   105     return self;
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CESMRStoreMRTask::ConstructL
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CESMRStoreMRTask::ConstructL()
       
   113     {
       
   114     FUNC_LOG;
       
   115     BaseConstructL();
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CESMRStoreMRTask::ExecuteTaskL
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CESMRStoreMRTask::ExecuteTaskL()
       
   123     {
       
   124     FUNC_LOG;
       
   125 
       
   126     // Store to calendar DB
       
   127     StoreEntryToDbL();
       
   128 
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CESMRStoreMRTask::StoreEntryToDbL
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CESMRStoreMRTask::StoreEntryToDbL()
       
   136     {
       
   137     FUNC_LOG;
       
   138 
       
   139     MESMRMeetingRequestEntry& mrEntry = ESMREntry();
       
   140     CCalEntry& entry = mrEntry.Entry();
       
   141 
       
   142     const CCalEntry::TType KMRType(
       
   143             CCalEntry::EAppt );
       
   144 
       
   145     CCalEntry::TType entryType( entry.EntryTypeL() );
       
   146 
       
   147     // Check entry type
       
   148 #ifdef _DEBUG
       
   149 
       
   150     __ASSERT_DEBUG(
       
   151             KMRType == entryType,
       
   152             Panic(EESMRStoreMRNotMeetingRequest) );
       
   153 
       
   154 #else
       
   155 
       
   156     if ( KMRType != entryType )
       
   157         {
       
   158         User::Leave( KErrArgument );
       
   159         }
       
   160 
       
   161 #endif // _DEBUG
       
   162 
       
   163     TBool isEdited( mrEntry.IsEntryEditedL() );
       
   164     TBool forwarded( mrEntry.IsForwardedL() );
       
   165     
       
   166     if ( !forwarded )
       
   167     	{
       
   168     	if ( isEdited )
       
   169     	    {
       
   170     	    // Entry is edited --> We will update time stamp
       
   171     	    mrEntry.UpdateTimeStampL();
       
   172     	    }
       
   173     	
       
   174 		// Check storing result
       
   175 		MESMRUtilsTombsExt::TESMRUtilsDbResult res =
       
   176 				CalDbMgr().StoreEntryCondL( entry, EFalse, ETrue );
       
   177 	
       
   178 		// Check that entry can be saved
       
   179 		if ( MESMRUtilsTombsExt::ECheckedValidNew == res ||
       
   180 			 MESMRUtilsTombsExt::ECheckedValidUpdate == res || 
       
   181 			 isEdited )
       
   182 			{
       
   183 			CCalEntry* validatedEntry = mrEntry.ValidateEntryL();
       
   184 			CleanupStack::PushL( validatedEntry );
       
   185 			
       
   186 			CalDbMgr().StoreEntryCondL( *validatedEntry, EFalse );
       
   187 			
       
   188 			CleanupStack::PopAndDestroy( validatedEntry );
       
   189 			
       
   190 			mrEntry.UpdateEntryAfterStoringL();
       
   191 			}
       
   192     	}
       
   193 
       
   194     }
       
   195 
       
   196 // EOF
       
   197