meetingui/meetingrequestutils/inc/CMRUtilsCalDbMgr.h
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:  
       
    15 *       Specifies interface for taking care of db actions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __CMRUTILSCALDBMGR_H__
       
    22 #define __CMRUTILSCALDBMGR_H__
       
    23 
       
    24 //  INCLUDES
       
    25 #include <e32base.h>
       
    26 #include "CMRUtilsInternal.h"
       
    27 #include <calprogresscallback.h>
       
    28 #include "CMRUtilsCalDbBase.h"
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class CCalSession;
       
    32 class CCalEntry;
       
    33 class MMRUtilsObserver;
       
    34 class CMRUtilsCmdIterationAO;
       
    35 class CMRUtilsGraveyardCleaner;
       
    36 
       
    37 // CLASS DECLARATION
       
    38 
       
    39 /**
       
    40 * Interface for taking care of db actions.
       
    41 */
       
    42 class MMRUtilsCalDbMgr : public MCalProgressCallBack
       
    43     {
       
    44     public: // Constructors and destructors
       
    45     
       
    46         /**
       
    47         * Destructor.
       
    48         */
       
    49         virtual ~MMRUtilsCalDbMgr() {};    
       
    50             
       
    51      public: // New functions
       
    52      
       
    53         /**
       
    54         * @see CMRUtils
       
    55         */     
       
    56         virtual CCalEntryView* NormalDbEntryView() = 0;
       
    57 
       
    58         /**
       
    59         * @see CMRUtils
       
    60         */     
       
    61         virtual CCalInstanceView* NormalDbInstanceView() = 0;
       
    62 
       
    63         /**
       
    64         * @see CMRUtils
       
    65         */     
       
    66         virtual void FetchEntriesL(
       
    67             RPointerArray<CCalEntry>& aCalEntryArray,
       
    68             const CalCommon::TCalTimeRange& aTimeRange ) = 0;
       
    69           
       
    70         /**
       
    71         * @see CMRUtils
       
    72         */     
       
    73         virtual CCalEntry* FetchEntryL( const TDesC8& aUid,
       
    74                                         const TCalTime& aRecurrenceId ) = 0;
       
    75 
       
    76         /**
       
    77         * @see CMRUtils
       
    78         */        
       
    79         virtual TInt StoreEntryL( CCalEntry& aCalEntry,
       
    80                                   TBool aToNormalDb = ETrue ) = 0;
       
    81         
       
    82         /**
       
    83         * @see CMRUtils
       
    84         */        
       
    85         virtual TInt UpdateEntryL( const CCalEntry& aCalEntry ) = 0;
       
    86         
       
    87         /**
       
    88         * @see CMRUtils
       
    89         */        
       
    90         virtual TInt DeleteEntryL( const TDesC8& aUid ) = 0;
       
    91         
       
    92         /**
       
    93         * @see CMRUtils
       
    94         */              
       
    95         virtual TInt DeleteEntryL( const TCalLocalUid& aLocalUid ) = 0;
       
    96 
       
    97         /**
       
    98         * @see CMRUtils
       
    99         */                
       
   100         virtual void ResetTombsFileL() = 0;
       
   101         
       
   102         /**
       
   103         * @see CMRUtils
       
   104         */                
       
   105         virtual void DeleteTombstonesL(
       
   106             const CalCommon::TCalTimeRange& aCalTimeRange ) = 0;
       
   107 
       
   108         /**
       
   109         * @see CMRUtils
       
   110         */                                     
       
   111         virtual MMRUtilsTombsExt::TMRUtilsDbResult StoreEntryCondL(
       
   112             CCalEntry& aCalEntry,
       
   113             TBool aResurrect,
       
   114             TBool aCheckOnly = EFalse ) = 0;
       
   115 
       
   116         /**
       
   117         * @see CMRUtils
       
   118         */        
       
   119         virtual void DeleteEntryCondL( const TDesC8& aUid ) = 0;
       
   120         
       
   121         /**
       
   122         * @see CMRUtils
       
   123         */                
       
   124         virtual void DeleteEntryCondL( const TCalLocalUid& aLocalUid ) = 0;
       
   125 
       
   126         /**
       
   127         * @see CMRUtils
       
   128         */        
       
   129         virtual void DeleteEntryCondL( const CCalEntry& aCalEntry ) = 0;
       
   130         
       
   131         /**
       
   132         * @see CMRUtils
       
   133         */                
       
   134         virtual void DeleteEntryCondL(
       
   135             const CalCommon::TCalTimeRange& aCalTimeRange ) = 0;
       
   136     };
       
   137 
       
   138 /**
       
   139 * Manages two databases: normal Agenda db and tombstone db, and
       
   140 * handles command logic related to these databases. This class is
       
   141 * also responsible for collecting both database status information
       
   142 * and async command progress, and to notify aObserver.
       
   143 */
       
   144 class CMRUtilsCalDbMgr
       
   145 : public CBase, 
       
   146   public MMRUtilsCalDbMgr,
       
   147   public MMRUtilsCalDbObserver
       
   148     {
       
   149     public: // Constructors and destructors
       
   150 
       
   151         /**
       
   152         * Symbian two-phased constructor.
       
   153         * @aCalSession calendar session reference
       
   154         * @aObserver utility observer reference
       
   155         */
       
   156         static CMRUtilsCalDbMgr* NewL( CCalSession& aCalSession,
       
   157                                        MMRUtilsObserver& aObserver );        
       
   158 
       
   159         /**
       
   160         * Destructor.
       
   161         */
       
   162         ~CMRUtilsCalDbMgr();
       
   163         
       
   164     protected: // From MMRUtilsCalDbObserver
       
   165     
       
   166     	void HandleCalDbStatus( const CMRUtilsCalDbBase* aNotifier,
       
   167     	                        MMRUtilsCalDbObserver::TDbStatus aStatus );
       
   168 
       
   169     protected: // From MCalProgressCallBack
       
   170     
       
   171     	void Progress( TInt aPercentageCompleted );
       
   172 		
       
   173         TBool NotifyProgress();
       
   174         
       
   175         void Completed( TInt aError );    	                            
       
   176 
       
   177     protected: // From MMRUtilsCalDbMgr
       
   178     
       
   179         CCalEntryView* NormalDbEntryView();
       
   180         
       
   181         CCalInstanceView* NormalDbInstanceView();
       
   182     
       
   183         void FetchEntriesL( RPointerArray<CCalEntry>& aCalEntryArray,
       
   184                             const CalCommon::TCalTimeRange& aTimeRange );
       
   185 
       
   186         CCalEntry* FetchEntryL( const TDesC8& aUid,
       
   187                                 const TCalTime& aRecurrenceId );
       
   188         
       
   189         TInt StoreEntryL( CCalEntry& aCalEntry,
       
   190                           TBool aToNormalDb = ETrue );
       
   191         
       
   192         TInt UpdateEntryL( const CCalEntry& aCalEntry );
       
   193         
       
   194         TInt DeleteEntryL( const TDesC8& aUid );
       
   195         
       
   196         TInt DeleteEntryL( const TCalLocalUid& aLocalUid );
       
   197 
       
   198         void ResetTombsFileL();
       
   199         
       
   200         void DeleteTombstonesL( const CalCommon::TCalTimeRange& aCalTimeRange );
       
   201                                 
       
   202         MMRUtilsTombsExt::TMRUtilsDbResult StoreEntryCondL(
       
   203             CCalEntry& aCalEntry,
       
   204             TBool aResurrect,
       
   205             TBool aCheckOnly = EFalse );
       
   206 	
       
   207         MMRUtilsTombsExt::TMRUtilsDbResult CheckEntryCondL( 
       
   208             const CCalEntry& aCalEntry );
       
   209 	
       
   210         void DeleteEntryCondL( const TDesC8& aUid );
       
   211         
       
   212         void DeleteEntryCondL( const TCalLocalUid& aLocalUid );
       
   213 		
       
   214         void DeleteEntryCondL( const CCalEntry& aCalEntry );
       
   215         
       
   216         void DeleteEntryCondL(
       
   217             const CalCommon::TCalTimeRange& aCalTimeRange );
       
   218 
       
   219     protected: // New functions
       
   220     
       
   221         /**
       
   222         * Tests whether entry with same GUID and RECURRENCE-ID exists
       
   223         * in aDb. If yes, then aIndex will tell it's position in aCalEntryArray
       
   224         * which contains all entries with the same GUID.
       
   225         * @param aUid first identity criterion
       
   226         * @param aRecurrenceId second identity criterion
       
   227         * @param aDb database where to look
       
   228         * @param aCalEntryArray contains all entries with same GUID
       
   229         * @param aIndex tells position of entry, if method returned ETrue
       
   230         * @return ETrue if entry exists in aDb                                        
       
   231         */
       
   232         TBool EntryExistsInDbL( const TDesC8& aUid,
       
   233                                 const TCalTime& aRecurrenceId,
       
   234                                 const CMRUtilsCalDbBase& aDb,
       
   235                                 RPointerArray<CCalEntry>& aCalEntryArray, 
       
   236                                 TInt& aIndex ) const;        
       
   237         /**
       
   238         * Tests whether entry with same GUID and RECURRENCE-ID exists
       
   239         * in aDb. If yes, then aIndex will tell it's position in aCalEntryArray
       
   240         * which contains all entries with the same GUID.
       
   241         * @param aEntry, whose GUID and RECURRENCE-ID are compared        
       
   242         * @param aDb database where to look
       
   243         * @param aCalEntryArray contains all entries with same GUID
       
   244         * @param aIndex tells position of entry, if method returned ETrue
       
   245         * @return ETrue if entry exists in aDb                                                
       
   246         */                
       
   247         TBool EntryExistsInDbL( const CCalEntry& aEntry,
       
   248                                 const CMRUtilsCalDbBase& aDb,
       
   249                                 RPointerArray<CCalEntry>& aCalEntryArray, 
       
   250                                 TInt& aIndex ) const;
       
   251     
       
   252         /**
       
   253         * Helper method for evaluating validity and status of entry
       
   254         * in relation to an another entry which exists in a database.
       
   255         * @param aEntry entry to be evaluated
       
   256         * @param aDbEntry corresponding entry existing in a database
       
   257         * @return entry evaluation result
       
   258         */                                                                                       
       
   259         MMRUtilsTombsExt::TMRUtilsDbResult EvaluateExistingEntryL(
       
   260             const CCalEntry& aEntry,
       
   261             const CCalEntry& aDbEntry ) const;
       
   262             
       
   263         /**
       
   264         * Helper method for evaluating validity and status of a new entry.
       
   265         * @aEntry entry to be evaluated
       
   266         * @return entry evaluation result
       
   267         */                            
       
   268         MMRUtilsTombsExt::TMRUtilsDbResult EvaluateNewEntryL(
       
   269             const CCalEntry& aEntry ) const;
       
   270                         
       
   271         /**
       
   272         * Helper method which checks if given child entry would be a
       
   273         * valid new modifying entry, i.e. if it has a recurrence id
       
   274         * which matches to an existing instance.
       
   275         * @param aEntry entry to be evaluated
       
   276         * @return ETrue if valid
       
   277         */
       
   278         TBool IsValidNewModL( const CCalEntry& aEntry ) const;
       
   279                       
       
   280         /**
       
   281         * Evaluates if corresponding originating entry exists in database.
       
   282         * @param aEntry 
       
   283         * @return ETrue if originating entry exists in database
       
   284         */
       
   285         TBool OriginatingExistInDbL( const CCalEntry& aModEntry );    
       
   286         
       
   287         /**
       
   288         * Helper method for deleting a tombstone entry.
       
   289         * @param aEntry entry to be deleted
       
   290         */
       
   291         void DeleteTombstoneL( const CCalEntry& aEntry );
       
   292         
       
   293     protected: // Constructors and destructors
       
   294     
       
   295         /**
       
   296         * C++ default constructor.
       
   297         * @param aCalSession calendar session reference
       
   298         * @param aObserver utility observer reference
       
   299         */
       
   300         CMRUtilsCalDbMgr( CCalSession& aCalSession,
       
   301                           MMRUtilsObserver& aObserver );
       
   302 
       
   303         /**
       
   304         *  Constructor, second phase.
       
   305         */
       
   306         void ConstructL();            
       
   307         
       
   308     protected: // data
       
   309     
       
   310         // Currently ongoing asynchronous utils operation
       
   311         TInt iCurrentAsyncOp;
       
   312     
       
   313         // Calendar session reference
       
   314         CCalSession& iCalSession;
       
   315     
       
   316         MMRUtilsObserver& iObserver;
       
   317         
       
   318         // Normal agenda database, own
       
   319         CMRUtilsCalDbBase* iNormalDb;
       
   320         
       
   321         // Tombstone database, own
       
   322         CMRUtilsCalDbBase* iTombsDb;
       
   323         
       
   324         // Handles asynchronous operation iteration, own
       
   325         CMRUtilsCmdIterationAO* iCmdIterator;
       
   326         
       
   327         // Cleans up tombstones when system is idle, own
       
   328         CMRUtilsGraveyardCleaner* iGraveyardCleaner;
       
   329     };
       
   330 
       
   331 #endif // __CMRUTILSCALDBMGR_H__
       
   332 
       
   333 // End of File