phonebookengines/VirtualPhonebook/VPbkCntModel/src/CContactStoreInfo.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63: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:  A store info implementation for the contact model
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CContactStoreInfo.h"
       
    22 
       
    23 #include "CContactStore.h"
       
    24 #include "CContactStoreDomain.h"
       
    25 #include <MVPbkFieldType.h>
       
    26 #include <MVPbkContactStoreProperties.h>
       
    27 #include <cntdb.h>
       
    28 
       
    29 namespace VPbkCntModel {
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CContactStoreInfo::CContactStoreInfo
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CContactStoreInfo::CContactStoreInfo(CContactStore& aStore,
       
    40         CContactStoreDomain& aDomain)
       
    41         :   iStore(aStore),
       
    42             iDomain(aDomain)
       
    43     {
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CContactStoreInfo::NewL
       
    48 // Two-phased constructor.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CContactStoreInfo* CContactStoreInfo::NewL(CContactStore& aStore,
       
    52         CContactStoreDomain& aDomain)
       
    53     {
       
    54     return new(ELeave) CContactStoreInfo(aStore,aDomain);
       
    55     }
       
    56     
       
    57 // Destructor
       
    58 CContactStoreInfo::~CContactStoreInfo()
       
    59     {
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CContactStoreInfo::MaxNumberOfContactsL
       
    64 // -----------------------------------------------------------------------------
       
    65 //        
       
    66 TInt CContactStoreInfo::MaxNumberOfContactsL() const
       
    67     {
       
    68     return KVPbkStoreInfoUnlimitedNumber;
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CContactStoreInfo::NumberOfContactsL
       
    73 // -----------------------------------------------------------------------------
       
    74 //                
       
    75 TInt CContactStoreInfo::NumberOfContactsL() const
       
    76     {
       
    77     return iStore.NativeDatabase().CountL() - NumberOfGroupsL();
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CContactStoreInfo::ReservedMemoryL
       
    82 // -----------------------------------------------------------------------------
       
    83 //        
       
    84 TInt64 CContactStoreInfo::ReservedMemoryL() const
       
    85     {
       
    86     return iStore.NativeDatabase().FileSize();
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CContactStoreInfo::FreeMemoryL
       
    91 // -----------------------------------------------------------------------------
       
    92 //        
       
    93 TInt64 CContactStoreInfo::FreeMemoryL() const
       
    94     {
       
    95     TDriveUnit driveUnit;
       
    96     iStore.NativeDatabase().DatabaseDrive(driveUnit);
       
    97     
       
    98     TVolumeInfo volInfo;
       
    99     User::LeaveIfError(iDomain.FsSession().Volume(volInfo,driveUnit));
       
   100     return volInfo.iFree;
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CContactStoreInfo::MaxNumberOfGroupsL
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 TInt CContactStoreInfo::MaxNumberOfGroupsL() const
       
   108     {
       
   109     return KVPbkStoreInfoUnlimitedNumber;
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CContactStoreInfo::NumberOfGroupsL
       
   114 // -----------------------------------------------------------------------------
       
   115 //        
       
   116 TInt CContactStoreInfo::NumberOfGroupsL() const
       
   117     {
       
   118     if( !iGroupsFetched )
       
   119         {
       
   120         CContactIdArray* arr = iStore.NativeDatabase().GetGroupIdListL();
       
   121         iGroupsFetched = ETrue;
       
   122         const TInt count = arr->Count();
       
   123         delete arr;
       
   124         return count;
       
   125         }
       
   126     return iStore.NativeDatabase().GroupCount();
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CContactStoreInfo::ResetGroupsFetched
       
   131 // -----------------------------------------------------------------------------
       
   132 //     
       
   133 void CContactStoreInfo::ResetGroupsFetched()
       
   134     {
       
   135     iGroupsFetched = EFalse;
       
   136     }
       
   137     
       
   138 } // namespace VPbkCntModel
       
   139 //  End of File