phonebookengines/VirtualPhonebook/VPbkCntModel/inc/CContactStore.h
branchRCL_3
changeset 20 f4a778e096c2
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Contacts Model store contact store implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef VPBKCNTMODEL_CCONTACTSTORE_H
       
    20 #define VPBKCNTMODEL_CCONTACTSTORE_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <MVPbkContactStore.h>
       
    25 #include <MVPbkContactStore2.h>
       
    26 #include <MVPbkContactOperationFactory.h>
       
    27 #include <VPbkFieldType.hrh>
       
    28 #include <MVPbkContactStoreObserver.h>
       
    29 #include <cntdb.h>
       
    30 #include <cntviewbase.h>
       
    31 #include "CContactStoreDomain.h"
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 class MVPbkFieldType;
       
    35 class CVPbkContactStoreUri;
       
    36 class MVPbkContactLink;
       
    37 class MVPbkContactObserver;
       
    38 class CVPbkContactStoreProperties;
       
    39 class MVPbkContactBookmark;
       
    40 template<typename MVPbkContactStoreObserver> class CVPbkAsyncObjectOperation;
       
    41 
       
    42 namespace VPbkEngUtils {
       
    43 class CVPbkDiskSpaceCheck;
       
    44 } /// namespace
       
    45 
       
    46 namespace VPbkCntModel {
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 class CFieldTypeMap;
       
    50 class CContact;
       
    51 class CFieldFactory;
       
    52 class CAsyncContactOperation;
       
    53 class CFieldsInfo;
       
    54 class CContactStoreInfo;
       
    55 class CNamedRemoteViewHandle;
       
    56 class CContactStoreOpenOperation;
       
    57 
       
    58 #ifdef _DEBUG
       
    59 enum TContactStorePanic
       
    60 	{
       
    61 	EPreCond_NativeDatabase,
       
    62 	EPreCond_ContactDestroyed,
       
    63 	EPreCond_CreateNewContactGroupLC,
       
    64 	EPreCond_ContactGroupsLC,
       
    65 	EPreCond_OwnContactLinkL,
       
    66 	EPreCond_OpenOperationState
       
    67 	};
       
    68 
       
    69 void ContactStorePanic( TContactStorePanic aPanic );
       
    70 #endif // _DEBUG
       
    71 
       
    72 
       
    73 // CLASS DECLARATIONS
       
    74 
       
    75 /**
       
    76  * Maps a Contact Model database to a virtual Phonebook contact store.
       
    77  */
       
    78 NONSHARABLE_CLASS( CContactStore ): public CBase,
       
    79                                     public MVPbkContactStore,
       
    80                                     public MVPbkContactStore2,
       
    81                                     private MContactDbObserver
       
    82     {
       
    83     public: // Constructor and destructor
       
    84         /**
       
    85          * Creates a new instance of this class.
       
    86          *
       
    87          * @param aURI          Filename URI of the Contacts Model
       
    88          *                      database to map.
       
    89          * @param aStoreDomain  Contact store domain.
       
    90          * @return  A new instance of this class.
       
    91          */
       
    92         static CContactStore* NewL(
       
    93                 const TVPbkContactStoreUriPtr& aURI,
       
    94                 CContactStoreDomain& aStoreDomain );
       
    95 
       
    96         /**
       
    97          * Destructor.
       
    98          */
       
    99         ~CContactStore();
       
   100 
       
   101     public: // Interface
       
   102         /**
       
   103          * Returns the field type map to use for mapping Contact Model field
       
   104          * types to Virtual Phonebook field types.
       
   105          *
       
   106          * @return  Field type map.
       
   107          */
       
   108         const CFieldTypeMap& FieldTypeMap() const;
       
   109 
       
   110         /**
       
   111          * Returns the field factory.
       
   112          *
       
   113          * @return  Field factory.
       
   114          */
       
   115         const CFieldFactory& FieldFactory() const;
       
   116 
       
   117         /**
       
   118          * Returns the master field type list of Virtual Phonebook.
       
   119          *
       
   120          * @return  Master field type list.
       
   121          */
       
   122         const MVPbkFieldTypeList& MasterFieldTypeList() const;
       
   123 
       
   124         /**
       
   125          * Creates and returns a new Contacts Model field based on Virtual
       
   126          * Phonebook generic field type.
       
   127          *
       
   128          * @param aFieldType    Field type.
       
   129          * @return  Contacts Model field.
       
   130          */
       
   131         CContactItemField* CreateFieldLC(
       
   132                 const MVPbkFieldType& aFieldType ) const;
       
   133 
       
   134         /**
       
   135          * Reads a contact from the database.
       
   136          *
       
   137          * @param aContactId    Id of the contact to read.
       
   138          * @param aObserver     Observer.
       
   139          */
       
   140         void ReadContactL(
       
   141                 TContactItemId aContactId,
       
   142                 MVPbkContactObserver& aObserver );
       
   143 
       
   144         /**
       
   145          * Locks a contact in the database.
       
   146          *
       
   147          * @param aClient   The contact to lock.
       
   148          * @param aObserver Observer.
       
   149          */
       
   150         void LockContactL(
       
   151                 const CContact& aClient,
       
   152                 MVPbkContactObserver& aObserver );
       
   153 
       
   154         /**
       
   155          * Reads and locks a contact in the database.
       
   156          *
       
   157          * @param aContactId    Id of the contact to read and lock.
       
   158          * @param aObserver     Observer.
       
   159          */
       
   160         void ReadAndLockContactL(
       
   161                 TContactItemId aContactId,
       
   162                 MVPbkContactObserver& aObserver );
       
   163 
       
   164         /**
       
   165          * Deletes a contact from the database.
       
   166          *
       
   167          * @param aContactId    Id of the contact to delete.
       
   168          * @param aObserver     Observer.
       
   169          */
       
   170         void DeleteContactL(
       
   171                 TContactItemId aContactId,
       
   172                 MVPbkContactObserver& aObserver );
       
   173 
       
   174         /**
       
   175          * Commits changes to a contact to the database.
       
   176          *
       
   177          * @param aContactItem  The contact to commit.
       
   178          * @param aObserver     Observer.
       
   179          */
       
   180         void CommitContactL(
       
   181                 const CContact& aContactItem,
       
   182                 MVPbkContactObserver& aObserver );
       
   183 
       
   184         /**
       
   185          * Creates a contact link.
       
   186          *
       
   187          * @param aContactId    Id of the contact to link.
       
   188          * @return  Contact link.
       
   189          */
       
   190         MVPbkContactLink* CreateLinkLC(
       
   191                 TContactItemId aContactId ) const;
       
   192 
       
   193         /**
       
   194          * Called from CContact destructor. aCloseContact should be
       
   195          * set for contacts that were locked. Read-only contacts
       
   196          * should provide EFalse for aCloseContact in order to avoid
       
   197          * resetting lock of another CContact instance for the same
       
   198          * contact model item.
       
   199          *
       
   200          * @param aContactItem  The destroyed contact.
       
   201          * @param aCloseContact Indicates that contact should be closed,
       
   202          * 						necessary for locked contacts.
       
   203          */
       
   204         void ContactDestroyed(
       
   205                 CContactItem* aContactItem, TBool aCloseContact );
       
   206 
       
   207         /**
       
   208          * Returns the native contacts database that
       
   209          * this store is connected to.
       
   210          *
       
   211          * @return  Contact database.
       
   212          */
       
   213         CContactDatabase& NativeDatabase() const;
       
   214 
       
   215         /**
       
   216          * Compares contact stores.
       
   217          *
       
   218          * @param aContactStoreUri  The URI to compare.
       
   219          * @return  ETrue if this is the same store.
       
   220          */
       
   221         TBool MatchContactStore(
       
   222                 const TDesC& aContactStoreUri ) const;
       
   223 
       
   224         /**
       
   225          * Compares contact store domains.
       
   226          *
       
   227          * @param aContactStoreDomain   The domain to compare.
       
   228          * @return  ETrue if this store is in the same domain.
       
   229          */
       
   230         TBool MatchContactStoreDomain(
       
   231                 const TDesC& aContactStoreDomain ) const;
       
   232 
       
   233         /**
       
   234          * Creates a contact bookmark
       
   235          *
       
   236          * @param aContactId    Id of the contact to bookmark.
       
   237          * @return  Contact bookmark.
       
   238          */
       
   239         MVPbkContactBookmark* CreateBookmarkLC(
       
   240                 TContactItemId aContactId ) const;
       
   241 
       
   242         /**
       
   243          * Set contact as the store's current own contact.
       
   244          *
       
   245          * @param aContactItem  The contact to set as own.
       
   246          * @param aObserver     Observer.
       
   247          */
       
   248         void SetAsOwnL(
       
   249                 const CContact& aContactItem,
       
   250                 MVPbkContactObserver& aObserver );
       
   251 
       
   252         /**
       
   253          * Asynchronous store opening is complete. 
       
   254          * 
       
   255          * @see CContactStoreOpenOperation.
       
   256          * @param aDB Opened native contacts store database.
       
   257          */
       
   258         void StoreOpenedL( CContactDatabase* aDB );
       
   259         
       
   260         /**
       
   261          * Asynchronous store opening has failed.
       
   262          * 
       
   263          * @see CContactStoreOpenOperation.
       
   264          * @param aError Generic synbian error code.
       
   265          */
       
   266         void StoreOpenFailed( TInt aError );
       
   267         
       
   268         /**
       
   269          * Request free disk space.
       
   270          * NOTE: Request is put on cleanupstack only if return value is ETrue.
       
   271          * 
       
   272          * @param aSpace Amount of free space requested.
       
   273          * @return ETrue if request was successful. 
       
   274          */
       
   275         TBool RequestFreeDiskSpaceLC( TInt aSpace );
       
   276         
       
   277     public: // From MVPbkContactStore
       
   278         const MVPbkContactStoreProperties& StoreProperties() const;
       
   279         void OpenL(
       
   280                 MVPbkContactStoreObserver& aObserver );
       
   281         void ReplaceL(
       
   282                 MVPbkContactStoreObserver& aObserver );
       
   283         void Close(
       
   284                 MVPbkContactStoreObserver& aObserver );
       
   285         MVPbkStoreContact* CreateNewContactLC();
       
   286         MVPbkContactGroup* CreateNewContactGroupLC();
       
   287         MVPbkContactView* CreateViewLC(
       
   288                 const CVPbkContactViewDefinition& aViewDefinition,
       
   289                 MVPbkContactViewObserver& aObserver,
       
   290                 const MVPbkFieldTypeList& aSortOrder );
       
   291         MVPbkContactLinkArray* ContactGroupsLC() const;
       
   292         const MVPbkContactStoreInfo& StoreInfo() const;
       
   293         MVPbkContactLink* CreateLinkFromInternalsLC(
       
   294                 RReadStream& aStream ) const;
       
   295         TAny* ContactStoreExtension( TUid aExtensionUid );
       
   296 
       
   297     public: // From MVPbkContactStore2
       
   298         MVPbkContactOperationBase* OwnContactLinkL(
       
   299                MVPbkSingleContactLinkOperationObserver& aObserver) const;
       
   300         
       
   301     public: // Contact operations (MVPbkContactOperationFactory)
       
   302         MVPbkContactOperation* CreateContactRetrieverL(
       
   303                 const MVPbkContactLink& aLink,
       
   304                 MVPbkSingleContactOperationObserver& aObserver );
       
   305         MVPbkContactOperation* CreateDeleteContactsOperationL(
       
   306                 const MVPbkContactLinkArray& aContactLinks,
       
   307                 MVPbkBatchOperationObserver& aObserver );
       
   308         MVPbkContactOperation* CreateCommitContactsOperationL(
       
   309                 const TArray<MVPbkStoreContact*>& aContacts,
       
   310                 MVPbkBatchOperationObserver& aObserver );
       
   311         MVPbkContactOperation* CreateMatchPhoneNumberOperationL(
       
   312                 const TDesC& aPhoneNumber,
       
   313                 TInt aMaxMatchDigits,
       
   314                 MVPbkContactFindObserver& aObserver );
       
   315         MVPbkContactOperation* CreateFindOperationL(
       
   316                 const TDesC& aSearchString,
       
   317                 const MVPbkFieldTypeList& aFieldTypes,
       
   318                 MVPbkContactFindObserver& aObserver );
       
   319         MVPbkContactOperation* CreateFindOperationL(
       
   320                 const MDesC16Array& aSearchStrings,
       
   321                 const MVPbkFieldTypeList& aFieldTypes,
       
   322                 MVPbkContactFindFromStoresObserver& aObserver,
       
   323                 const TCallBack& aWordParserCallBack );
       
   324         MVPbkContactOperation* CreateCompressStoresOperationL(
       
   325 			    MVPbkBatchOperationObserver& aObserver );
       
   326 
       
   327 
       
   328     public: // Interface for VPbkCntModel component
       
   329         void AddObserverL(
       
   330                 MVPbkContactStoreObserver& aObserver );
       
   331         void RemoveObserver(
       
   332                 MVPbkContactStoreObserver& aObserver );
       
   333         TBool IsOpened() const;
       
   334         RFs& ContactStoreDomainFsSession();
       
   335 
       
   336     private: // From MContactDbObserver
       
   337         void HandleDatabaseEventL(
       
   338                 TContactDbObserverEvent aEvent );
       
   339 
       
   340     private:  // Implementation
       
   341         CContactStore(
       
   342                 CContactStoreDomain& aStoreDomain );
       
   343         void ConstructL(
       
   344                 const TVPbkContactStoreUriPtr& aURI );
       
   345         void DoOpenL(
       
   346                 MVPbkContactStoreObserver& aObserver,
       
   347                 TBool aReplace );
       
   348         void OpenError(
       
   349                 MVPbkContactStoreObserver& aObserver,
       
   350                 TInt aError );
       
   351         void SetStaticPropertiesL();
       
   352         void DoAddFieldTypesL();
       
   353         void CloseSystemTemplate(
       
   354                 CContactDatabase* aContactDb );
       
   355         CContactDatabase* OpenInternalL();
       
   356         void DoActivateRemoteViewsL();
       
   357         RContactViewSortOrder CreateSortOrderL(
       
   358                 const MVPbkFieldTypeList& aSortOrder) const;
       
   359         TContactViewPreferences ConvertViewPrefsL(const TDesC8& aData);
       
   360 
       
   361     private:  // Data
       
   362         /// Ref: Store domain
       
   363         CContactStoreDomain& iStoreDomain;
       
   364         /// Own: URI of this store
       
   365         CVPbkContactStoreUri* iStoreURI;
       
   366         /// Own: Store properties
       
   367         CVPbkContactStoreProperties* iProperties;
       
   368         /// Own: Stores asynchronous operation
       
   369         CVPbkAsyncObjectOperation<MVPbkContactStoreObserver>* iAsyncOpenOp;
       
   370         /// Own: Store observers
       
   371         RPointerArray<MVPbkContactStoreObserver> iObservers;
       
   372         /// Own: Contact database for this store
       
   373         CContactDatabase* iContactDb;
       
   374         /// Own: Contact database change notifier
       
   375         CContactChangeNotifier* iDbNotifier;
       
   376         /// Own: Virtual Phonebook to contact model field type mapping
       
   377         CFieldFactory* iFieldFactory;
       
   378         /// Own: Asynchronous operation
       
   379         CAsyncContactOperation* iAsyncContactOperation;
       
   380         /// Own: Field info of Contacts Model fields
       
   381         CFieldsInfo* iFieldsInfo;
       
   382         /// Own: the store info
       
   383         CContactStoreInfo* iStoreInfo;
       
   384         /// Own: Golden template contact item
       
   385         CContactItem* iSysTemplate;
       
   386         /// Own: Disk space checker
       
   387         VPbkEngUtils::CVPbkDiskSpaceCheck* iDiskSpaceCheck;
       
   388         /// Own: named remote view container
       
   389         RPointerArray<CNamedRemoteViewHandle> iNamedViewContainer;
       
   390         /// Own: Contact store open operation
       
   391         CContactStoreOpenOperation* iOpenOperation;
       
   392         /// Has golden template been updated
       
   393         TBool iGoldenTemplateUpdated;
       
   394     };
       
   395 
       
   396 
       
   397 // INLINE FUNCTIONS
       
   398 
       
   399 inline CContactDatabase& CContactStore::NativeDatabase() const
       
   400     {
       
   401     __ASSERT_DEBUG( iContactDb, ContactStorePanic( EPreCond_NativeDatabase ) );
       
   402     return *iContactDb;
       
   403     }
       
   404 
       
   405 } /// namespace VPbkCntModel
       
   406 
       
   407 #endif  // VPBKCNTMODEL_CCONTACTSTORE_H
       
   408 
       
   409 //End of File
       
   410 
       
   411