meetingui/meetingrequestutils/src/CMRUtilsCalDbTombs.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2005 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 meeting request utils calendar db tombs  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ----------------------------------------------------------------------------
       
    21 // INCLUDE FILES
       
    22 // ----------------------------------------------------------------------------
       
    23 //
       
    24 #include "CMRUtilsCalDbTombs.h"
       
    25 #include <CalEntryView.h>
       
    26 #include <CalEntry.h>
       
    27 #include <CalCommon.h>
       
    28 #include <CalSession.h>
       
    29 #include <CalUser.h>
       
    30 
       
    31 // CONSTANTS
       
    32 /// Unnamed namespace for local definitions
       
    33 namespace {
       
    34 
       
    35 _LIT( KMRUtilsTombsDb, "c:tombstones" );
       
    36 
       
    37 enum TPanicCode
       
    38     {
       
    39     EPanicUnexpectedCalEngStatus = 1,
       
    40     EPanicEntryViewAlreadyExists
       
    41     };
       
    42 
       
    43 _LIT( KPanicMsg, "CMRUtilsCalDbTombs" );
       
    44 
       
    45 void Panic( TPanicCode aReason )
       
    46     {
       
    47     User::Panic( KPanicMsg, aReason );
       
    48     }
       
    49     
       
    50 }  // namespace
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // MEMBER FUNCTIONS
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // CMRUtilsCalDbTombs::NewL
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 CMRUtilsCalDbTombs* CMRUtilsCalDbTombs::NewL(
       
    62     MMRUtilsCalDbObserver& aDbObserver,
       
    63     MCalProgressCallBack& aCmdObserver )
       
    64 	{
       
    65 	CMRUtilsCalDbTombs* self =
       
    66 	    new( ELeave ) CMRUtilsCalDbTombs( aDbObserver, aCmdObserver );
       
    67 	CleanupStack::PushL( self );
       
    68 	self->ConstructL();
       
    69 	CleanupStack::Pop();
       
    70 	return self;
       
    71 	}
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // CMRUtilsCalDbTombs::CMRUtilsCalDbTombs
       
    75 //
       
    76 // Constructor.
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 CMRUtilsCalDbTombs::CMRUtilsCalDbTombs(
       
    80     MMRUtilsCalDbObserver& aDbObserver,
       
    81     MCalProgressCallBack& aCmdObserver )
       
    82     : CMRUtilsCalDbBase( aDbObserver, aCmdObserver )
       
    83     {
       
    84     
       
    85     }
       
    86     
       
    87 // ----------------------------------------------------------------------------
       
    88 // CMRUtilsCalDbTombs::~CMRUtilsCalDbTombs
       
    89 //
       
    90 // Destructor.
       
    91 // ----------------------------------------------------------------------------
       
    92 //        
       
    93 CMRUtilsCalDbTombs::~CMRUtilsCalDbTombs()
       
    94     {
       
    95     delete iCalEntryView;
       
    96     delete iCalSession;
       
    97     }
       
    98     
       
    99 // ----------------------------------------------------------------------------
       
   100 // CMRUtilsCalDbTombs::ConstructL
       
   101 // ----------------------------------------------------------------------------
       
   102 //    
       
   103 void CMRUtilsCalDbTombs::ConstructL()
       
   104     {
       
   105     // This subclass of CMRUtilsCalDbBase owns the session it creates:
       
   106     iCalSession = CCalSession::NewL();
       
   107     
       
   108     OpenTombsFileWithEntryViewL();
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------------------------------
       
   112 // CMRUtilsCalDbTombs::ResetDbL
       
   113 // ----------------------------------------------------------------------------
       
   114 //        
       
   115 void CMRUtilsCalDbTombs::ResetDbL()
       
   116     {
       
   117     iDbStatus = MMRUtilsCalDbObserver::EReseting;
       
   118     iDbObserver.HandleCalDbStatus( this, iDbStatus );
       
   119     
       
   120     // Close references
       
   121     // (it is caller's responsibility to have closed own references):
       
   122     delete iCalEntryView;
       
   123     iCalEntryView = NULL;
       
   124     
       
   125     iCalSession->DeleteCalFileL( KMRUtilsTombsDb );
       
   126     
       
   127     OpenTombsFileWithEntryViewL();
       
   128     }
       
   129 
       
   130 // ----------------------------------------------------------------------------
       
   131 // CMRUtilsCalDbTombs::Completed
       
   132 // ----------------------------------------------------------------------------
       
   133 //    
       
   134 void CMRUtilsCalDbTombs::Completed( TInt aError )
       
   135     {
       
   136     if ( aError == KErrNone )
       
   137         {
       
   138         __ASSERT_DEBUG( iDbStatus == MMRUtilsCalDbObserver::EInitEntryView,
       
   139                         Panic( EPanicUnexpectedCalEngStatus ) );             
       
   140         iDbStatus = MMRUtilsCalDbObserver::EFinishedOk;
       
   141         }
       
   142     else // aError != KErrNone
       
   143         { // Initialization error has occurred, tombs db not usable:
       
   144         iDbStatus = MMRUtilsCalDbObserver::EFinishedError;
       
   145         }
       
   146             
       
   147     // If either of the final states has been reached, then notify observer:            
       
   148     if ( iDbStatus == MMRUtilsCalDbObserver::EFinishedOk ||
       
   149          iDbStatus == MMRUtilsCalDbObserver::EFinishedError )
       
   150         {
       
   151         iDbObserver.HandleCalDbStatus( this, iDbStatus );            
       
   152         }    
       
   153     }
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CMRUtilsCalDbTombs::OpenTombsFileWithEntryViewL
       
   157 // ----------------------------------------------------------------------------
       
   158 //    
       
   159 void CMRUtilsCalDbTombs::OpenTombsFileWithEntryViewL()
       
   160     {    
       
   161     TRAPD( err, iCalSession->OpenL( KMRUtilsTombsDb ) );
       
   162     if ( err == KErrNotFound )
       
   163         {
       
   164         iCalSession->CreateCalFileL( KMRUtilsTombsDb );
       
   165         iCalSession->OpenL( KMRUtilsTombsDb ); // not trapped anymore
       
   166         }
       
   167     else
       
   168         {
       
   169         User::LeaveIfError( err );
       
   170         }
       
   171     
       
   172     __ASSERT_DEBUG( !iCalEntryView, Panic( EPanicEntryViewAlreadyExists ) );
       
   173     iCalEntryView = CCalEntryView::NewL( *iCalSession, *this );
       
   174     iDbStatus = MMRUtilsCalDbObserver::EInitEntryView;
       
   175     // See Completed() for continuation...        
       
   176     }
       
   177 
       
   178 // End of file