phonebookengines/VirtualPhonebook/VPbkLdapStore/src/ContactStore.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  CContactStore implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "contactstore.h"
       
    21 #include "contactstoredomain.h"
       
    22 #include "contactstoreinfo.h"
       
    23 #include "contactstoreproperties.h"
       
    24 #include "contactstoreuri.h"
       
    25 #include "contact.h"
       
    26 #include "ldapcontact.h"
       
    27 #include "contactlink.h"
       
    28 #include "contactretriever.h"
       
    29 #include "contactview.h"
       
    30 #include "supportedfieldtypes.h"
       
    31 
       
    32 #include "ldapfinderui.h"       // Finder UI
       
    33 #include "fieldtypemappings.h"  // Field type mapping
       
    34 #include "ldapfieldtype.h"      // LDAP Field type
       
    35 #include <barsc.h>              // For resource
       
    36 #include <barsread.h>           // For resource reader
       
    37 #include <mvpbkfieldtype.h>     // Field type list
       
    38 #include <ldapstoreres.rsg>     // Field type mapping resource
       
    39 
       
    40 #include <cvpbkcontactviewdefinition.h>
       
    41 #include <mvpbkcontactstoreobserver.h>
       
    42 #include <mvpbkcontactoperationfactory.h>
       
    43 
       
    44 // CONSTANTS
       
    45 _LIT(KLDAPDriveC,"c:");
       
    46 _LIT(KLDAPDriveZ,"z:");
       
    47 _LIT(KLDAPResourceFilesDir,"\\resource\\");
       
    48 _LIT(KLDAPStoreResFile,"LDAPStoreRes.rsc");
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // LDAPStoreInitializeL
       
    52 // Store initialized notify callback
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 static TInt LDAPStoreInitializeL(TAny* aThis)
       
    56     {
       
    57     if (aThis)
       
    58         {
       
    59         return static_cast<LDAPStore::CContactStore*>(aThis)->StoreInitializeL();
       
    60         }
       
    61     return EFalse;
       
    62     }
       
    63 // -----------------------------------------------------------------------------
       
    64 // LDAPStoreReady
       
    65 // Store ready notify callback
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 static TInt LDAPStoreReady(TAny* aThis)
       
    69     {
       
    70     if (aThis)
       
    71         {
       
    72         static_cast<LDAPStore::CContactStore*>(aThis)->StoreReady();
       
    73         }
       
    74     return EFalse;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // LDAP Store namespace
       
    79 // -----------------------------------------------------------------------------
       
    80 namespace LDAPStore {
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CContactStore::CContactStore
       
    84 // C++ default constructor can NOT contain any code, that might leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CContactStore::CContactStore(CContactStoreDomain& aStoreDomain)
       
    88 :   iStoreDomain(aStoreDomain)
       
    89     {
       
    90     // No implementation required
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CContactStore::ConstructL
       
    95 // CContactStore constructor for performing 2nd stage construction
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CContactStore::ConstructL(const TVPbkContactStoreUriPtr& aURI)
       
    99     {
       
   100     // Store properties
       
   101     iProperties = CContactStoreProperties::NewL();
       
   102 
       
   103     // Store uri - pure nonsense, but required
       
   104     iStoreURI = CContactStoreUri::NewL(aURI);
       
   105 
       
   106     // Set name, actually whole uri
       
   107     iProperties->SetName(iStoreURI->Uri());
       
   108 
       
   109     // Store information
       
   110     iStoreInfo = CContactStoreInfo::NewL(*this);
       
   111 
       
   112     // Settings loaded with store name
       
   113     iSettings = CLDAPSettings::NewL(iProperties->Name().UriDes());
       
   114 
       
   115     // Initialiaze field mappings of this store
       
   116     InitializeFieldMappingL();
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CContactStore::NewLC
       
   121 // CContactStore two-phased constructor.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CContactStore* CContactStore::NewLC(const TVPbkContactStoreUriPtr& aURI,
       
   125                                     CContactStoreDomain& aStoreDomain)
       
   126     {
       
   127     CContactStore* self = new (ELeave)CContactStore(aStoreDomain);
       
   128     CleanupStack::PushL(self);
       
   129     self->ConstructL(aURI);
       
   130     return self;
       
   131     }
       
   132 // -----------------------------------------------------------------------------
       
   133 // CContactStore::NewL
       
   134 // CContactStore two-phased constructor.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 CContactStore* CContactStore::NewL(const TVPbkContactStoreUriPtr& aURI,
       
   138                                    CContactStoreDomain& aStoreDomain)
       
   139     {
       
   140     CContactStore* self = CContactStore::NewLC(aURI,aStoreDomain);
       
   141     CleanupStack::Pop(self);
       
   142     return self;
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CContactStore::~CContactStore
       
   147 // CContactStore Destructor
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 CContactStore::~CContactStore()
       
   151     {
       
   152     // Close observers
       
   153     iStoreObservers.Close();
       
   154 
       
   155     // Callback
       
   156     if (iIdle)
       
   157         {
       
   158         // Cancel all pending operations
       
   159         iIdle->Cancel();
       
   160         delete iIdle;
       
   161         iIdle = NULL;
       
   162         }
       
   163 
       
   164     // Store directory
       
   165     if (iDirectory)
       
   166         {
       
   167         delete iDirectory;
       
   168         iDirectory = NULL;
       
   169         }
       
   170     // Settings
       
   171     if (iSettings)
       
   172         {
       
   173         delete iSettings;
       
   174         iSettings = NULL;
       
   175         }
       
   176     // Store URI
       
   177     if (iStoreURI)
       
   178         {
       
   179         delete iStoreURI;
       
   180         iStoreURI = NULL;
       
   181         }
       
   182     // Store properties
       
   183     if (iProperties)
       
   184         {
       
   185         delete iProperties;
       
   186         iProperties = NULL;
       
   187         }
       
   188     // Store information
       
   189     if (iStoreInfo)
       
   190         {
       
   191         delete iStoreInfo;
       
   192         iStoreInfo = NULL;
       
   193         }
       
   194 
       
   195     // Supported fields
       
   196     if (iSupportedFieldTypes)
       
   197         {
       
   198         delete iSupportedFieldTypes;
       
   199         iSupportedFieldTypes = NULL;
       
   200         }
       
   201 
       
   202     // Field type list
       
   203     iFieldTypes.Close();
       
   204 
       
   205     // Clear contacts
       
   206     iContacts.ResetAndDestroy();
       
   207     iContacts.Close();
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 //                      CContactStore public methods
       
   212 // -----------------------------------------------------------------------------
       
   213 // CContactStore::AddObserverL
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CContactStore::AddObserverL(MVPbkContactStoreObserver& aObserver)
       
   217     {
       
   218     // Already in observers
       
   219     TInt find = iStoreObservers.Find(&aObserver);
       
   220     if (find == KErrNotFound)
       
   221         {
       
   222         // Add observer
       
   223         iStoreObservers.AppendL(&aObserver);
       
   224         }
       
   225     }
       
   226 // -----------------------------------------------------------------------------
       
   227 // CContactStore::RemoveObserver
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CContactStore::RemoveObserver(MVPbkContactStoreObserver& aObserver)
       
   231     {
       
   232     const TInt pos = iStoreObservers.Find(&aObserver);
       
   233     if (pos != KErrNotFound)
       
   234         {
       
   235         iStoreObservers.Remove(pos);
       
   236         }
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CContactStore::CreateContactL
       
   241 // Creates new contact from index.
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 CContact* CContactStore::CreateContactL(TInt aIndex)
       
   245     {
       
   246     CContact* cp = NULL;
       
   247     // Index in range
       
   248     if (aIndex >= 0 && aIndex < iContacts.Count())
       
   249         {        
       
   250         // New contact
       
   251         cp = CContact::NewL(*this,ContactAt(aIndex).Contact(),EFalse);
       
   252         }
       
   253     return cp;
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CContactStore::ContactCount
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 TInt CContactStore::ContactCount()
       
   261     {
       
   262     return iContacts.Count();    
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CContactStore::ContactAt
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 CContact& CContactStore::ContactAt(TInt aIndex)
       
   270     {
       
   271     return *iContacts[aIndex];
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CContactStore::FieldTypeMappings
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 CFieldTypeMappings& CContactStore::FieldTypeMappings()
       
   279     {
       
   280     return iStoreDomain.FieldTypeMappings();
       
   281     }
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // CContactStore::IsInitialized
       
   285 // Returns true if store is initialized.
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 TBool CContactStore::IsInitialized() {
       
   289     return iState == EInitialized;
       
   290 }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CContactStore::IsOpen
       
   294 // Returns true if store is open.
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 TBool CContactStore::IsOpen()
       
   298     {
       
   299     return iState == EOpened;
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CContactStore::State
       
   304 // Returns store state.
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 CContactStore::TState CContactStore::State()
       
   308     {
       
   309     return iState;
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CContactStore::MatchContactStore
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 TBool CContactStore::MatchContactStore(const TDesC& aContactStoreUri) const
       
   317     {
       
   318     if (iStoreURI->Uri().Compare(TVPbkContactStoreUriPtr(aContactStoreUri), 
       
   319         TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) == 0)
       
   320         {
       
   321         return ETrue;
       
   322         }
       
   323     return EFalse;
       
   324     }
       
   325     
       
   326 // -----------------------------------------------------------------------------
       
   327 // CContactStore::MatchContactStoreDomain
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 TBool CContactStore::MatchContactStoreDomain(const TDesC& aContactStoreDomain) const
       
   331     {
       
   332     if (iStoreURI->Uri().Compare(aContactStoreDomain, 
       
   333         TVPbkContactStoreUriPtr::EContactStoreUriStoreType) == 0)
       
   334         {
       
   335         return ETrue;
       
   336         }
       
   337     return EFalse;
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // CContactStore::Name
       
   342 // Returns store name
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 TPtrC CContactStore::Name()
       
   346     {
       
   347     return (iSettings) ? iSettings->Name() : TPtrC(KNullDesC);
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CContactStore::StoreInitializeL
       
   352 // Initializes store
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 TBool CContactStore::StoreInitializeL()
       
   356     {
       
   357     TBool status = ETrue;
       
   358     // Just change state
       
   359     if (iState == EIdle)
       
   360         {
       
   361         iState = EInitializing;
       
   362         }
       
   363     else
       
   364     // Start initializing
       
   365     if (iState == EInitializing)
       
   366         {
       
   367         // Old directory
       
   368         if (iDirectory)
       
   369             {
       
   370             delete iDirectory;
       
   371             iDirectory = NULL;
       
   372             }
       
   373         // New directory
       
   374         iDirectory = LDAPEngine::CDirectory::NewL();
       
   375         // Add observer
       
   376         iDirectory->AddObserverL(*this);
       
   377         // Configure
       
   378         iDirectory->Configure(*iSettings);
       
   379         // Set field types
       
   380         iDirectory->SetSearchAttributesL(iFieldTypes);
       
   381         // Supported field types
       
   382         InitializeSupportedFieldsL();
       
   383         // Stop initializing
       
   384         status = EFalse;
       
   385         }
       
   386     return status;
       
   387     }
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 // CContactStore::StoreReady
       
   391 // -----------------------------------------------------------------------------
       
   392 //
       
   393 void CContactStore::StoreReady()
       
   394     {
       
   395     // Notify all - notice the reverse order
       
   396     for (TInt loop = iStoreObservers.Count() - 1; loop >= 0 ;loop--)
       
   397         {
       
   398         // Notify
       
   399         StoreReady(*iStoreObservers[loop]);
       
   400         }
       
   401     }
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 //                      CContactStore private methods
       
   405 // -----------------------------------------------------------------------------
       
   406 // CTestEngineAppUi::InitializeFieldMappingL
       
   407 // Initialiaze store field type mappings
       
   408 // -----------------------------------------------------------------------------
       
   409 void CContactStore::InitializeFieldMappingL()
       
   410     {  
       
   411     // For resource reading
       
   412     RFs fs;
       
   413     User::LeaveIfError(fs.Connect());
       
   414     CleanupClosePushL(fs);
       
   415 
       
   416     // Default resource file name
       
   417     TFileName res_name(KLDAPDriveZ);
       
   418     res_name.Append(KLDAPResourceFilesDir);
       
   419     res_name.Append(KLDAPStoreResFile);
       
   420 
       
   421     // Customized resource file
       
   422     TPtrC cus_name = iSettings->ResourceFile();
       
   423     if (cus_name.Length() > 0)
       
   424         {
       
   425         // Custom resource name
       
   426         TFileName cus_res;
       
   427 
       
   428         // Parse name
       
   429         TParse name_parser;
       
   430         name_parser.Set(cus_name,NULL,NULL);
       
   431 
       
   432         // Has drive
       
   433         TPtrC drive = name_parser.Drive();
       
   434         if (drive.Length() > 0)
       
   435             {
       
   436             // Add drive
       
   437             cus_res.Append(drive);
       
   438             }
       
   439         else
       
   440             {
       
   441             // Add default C drive
       
   442             cus_res.Append(KLDAPDriveC);
       
   443             }
       
   444 
       
   445         // Path present
       
   446         if (name_parser.PathPresent())
       
   447             {
       
   448             // Add path
       
   449             cus_res.Append(name_parser.Path());
       
   450             }
       
   451         else
       
   452             {
       
   453             // Add default
       
   454             cus_res.Append(KLDAPResourceFilesDir);
       
   455             }
       
   456 
       
   457         // Add name
       
   458         cus_res.Append(name_parser.NameAndExt());
       
   459         if (fs.IsValidName(cus_res))
       
   460             {
       
   461             // File attributes
       
   462             TUint attr = 0;
       
   463             TInt status = fs.Att(cus_res,attr);
       
   464             if (status == KErrNone)
       
   465                 {
       
   466                 // Replace name
       
   467                 res_name.Copy(cus_res);
       
   468                 }
       
   469             }
       
   470         }
       
   471 
       
   472     // Load field type mappings
       
   473     RResourceFile res_file;
       
   474     // Open resource
       
   475     res_file.OpenL(fs,res_name);
       
   476 
       
   477     // Check that resource has mapping list
       
   478     if (! res_file.OwnsResourceId(R_LDAP_FIELD_MAPPING_LIST))
       
   479         {
       
   480         // Close resource
       
   481         res_file.Close();
       
   482         // Custom resource
       
   483         if (cus_name.Length() > 0)
       
   484             {
       
   485             // Default resource
       
   486             res_name.Copy(KLDAPDriveZ);
       
   487             res_name.Append(KLDAPResourceFilesDir);
       
   488             res_name.Append(KLDAPStoreResFile);
       
   489             // Open resource
       
   490             res_file.OpenL(fs,res_name);
       
   491             }
       
   492         else
       
   493             {
       
   494             // File server
       
   495             CleanupStack::PopAndDestroy();
       
   496             return;
       
   497             }
       
   498         }
       
   499 
       
   500     // Push to close
       
   501     CleanupClosePushL(res_file);
       
   502 
       
   503     // Resource reader
       
   504     TResourceReader reader;
       
   505     // Search attribute list
       
   506     reader.SetBuffer(res_file.AllocReadLC(R_LDAP_FIELD_MAPPING_LIST));
       
   507 
       
   508     // Read field mapping list
       
   509     TInt count = reader.ReadInt16();
       
   510     while (count-- > 0)
       
   511         {
       
   512         // Read entries
       
   513         iFieldTypes.AppendL(TLDAPFieldType(reader));
       
   514         }
       
   515 
       
   516     // Cleanup - R_LDAP_FIELD_MAPPING_LIST
       
   517     CleanupStack::PopAndDestroy();
       
   518 
       
   519     // Close resource
       
   520     res_file.Close();
       
   521 
       
   522     // Resource file
       
   523     CleanupStack::PopAndDestroy();
       
   524     // File server
       
   525     CleanupStack::PopAndDestroy();
       
   526     }
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CTestEngineAppUi::InitializeSupportedFieldsL
       
   530 // Initialiaze store supported field types
       
   531 // -----------------------------------------------------------------------------
       
   532 void CContactStore::InitializeSupportedFieldsL()
       
   533     {
       
   534     // Clear supported fields
       
   535     if (iSupportedFieldTypes)
       
   536         {
       
   537         delete iSupportedFieldTypes;
       
   538         iSupportedFieldTypes = NULL;
       
   539         }
       
   540 
       
   541     // Supported fields
       
   542     iSupportedFieldTypes = CSupportedFieldTypes::NewL(iFieldTypes,
       
   543                                 iStoreDomain.FieldTypeMappings());
       
   544     // Set supported fields
       
   545     iProperties->SetSupportedFields(*iSupportedFieldTypes);
       
   546     }
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // CContactStore::StoreReady
       
   550 // -----------------------------------------------------------------------------
       
   551 //
       
   552 void CContactStore::StoreReady(MVPbkContactStoreObserver& aObserver)
       
   553     {
       
   554     aObserver.StoreReady(*this);
       
   555     }
       
   556 
       
   557 // -----------------------------------------------------------------------------
       
   558 // CContactStore::RetrieveContactsL
       
   559 // Creates contact records from directory.
       
   560 // -----------------------------------------------------------------------------
       
   561 //
       
   562 void CContactStore::RetrieveContactsL()
       
   563     {
       
   564     // Clear old results
       
   565     iContacts.ResetAndDestroy();
       
   566     // Results count
       
   567     TInt count = (iDirectory) ? iDirectory->Records() : 0;
       
   568     if (count > 0)
       
   569         {
       
   570         // Make new results
       
   571         for (TInt loop = 0;loop < count;loop++)
       
   572             {
       
   573             // LDAP contact
       
   574             CLDAPContact* lcp = iDirectory->CreateContactL(loop);
       
   575             if (lcp)
       
   576                 {
       
   577                 // Push to stack
       
   578                 CleanupStack::PushL(lcp);
       
   579 
       
   580                 // New contact
       
   581                 CContact* cp = CContact::NewLC(*this,lcp);
       
   582                 cp->SetIndex(loop);
       
   583 
       
   584                 // Add to contacts
       
   585                 iContacts.AppendL(cp);
       
   586 
       
   587                 // Pop stack
       
   588                 CleanupStack::Pop(cp);
       
   589                 CleanupStack::Pop(lcp);
       
   590                 }
       
   591             } // End of loop over results
       
   592 
       
   593         // Can release results
       
   594         if (iDirectory->CanReleaseResults())
       
   595             {
       
   596             // Clear results
       
   597             iDirectory->ReleaseResults();
       
   598             }
       
   599         else
       
   600             {
       
   601             // Set release results
       
   602             iDirectory->SetCanReleaseResults(ETrue);
       
   603             }
       
   604         }
       
   605     }
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 //              MVPbkContactOperationFactory implementation
       
   609 // -----------------------------------------------------------------------------
       
   610 // CContactStore::CreateContactRetrieverL
       
   611 // -----------------------------------------------------------------------------
       
   612 //
       
   613 MVPbkContactOperation* CContactStore::CreateContactRetrieverL( 
       
   614     const MVPbkContactLink& aLink,
       
   615     MVPbkSingleContactOperationObserver& aObserver
       
   616 )
       
   617     {
       
   618     // Contact link is from this store
       
   619     if (this == &aLink.ContactStore())
       
   620         {
       
   621         // Cast to contact link
       
   622         const CContactLink& link = static_cast<const CContactLink&>(aLink);
       
   623         // Contact retriever
       
   624         return CContactRetriever::NewL(*this,link.Index(),aObserver);
       
   625         }
       
   626     return NULL;
       
   627     }
       
   628 
       
   629 // -----------------------------------------------------------------------------
       
   630 // CContactStore::CreateDeleteContactsOperationL
       
   631 // -----------------------------------------------------------------------------
       
   632 //
       
   633 MVPbkContactOperation* CContactStore::CreateDeleteContactsOperationL(
       
   634     const MVPbkContactLinkArray& /* aContactLinks */, 
       
   635     MVPbkBatchOperationObserver& /* aObserver */
       
   636 )
       
   637     {
       
   638     // LDAP Store is read only
       
   639     return NULL;
       
   640     }
       
   641 
       
   642 // -----------------------------------------------------------------------------
       
   643 // CContactStore::CreateCommitContactsOperationL
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 MVPbkContactOperation* CContactStore::CreateCommitContactsOperationL(
       
   647     const TArray<MVPbkStoreContact*>& /* aContacts */,
       
   648     MVPbkBatchOperationObserver& /* aObserver */
       
   649 )
       
   650     {
       
   651     // LDAP Store is read only
       
   652     return NULL;
       
   653     }
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // CContactStore::CreateMatchPhoneNumberOperationL
       
   657 // -----------------------------------------------------------------------------
       
   658 //
       
   659 MVPbkContactOperation* CContactStore::CreateMatchPhoneNumberOperationL(
       
   660     const TDesC&           /* aPhoneNumber */,
       
   661     TInt               /*  aMaxMatchDigits */,
       
   662     MVPbkContactFindObserver& /* aObserver */
       
   663 )
       
   664     {
       
   665     return NULL;
       
   666     }
       
   667 
       
   668 // -----------------------------------------------------------------------------
       
   669 // CContactStore::CreateFindOperationL
       
   670 // Creates find operation.
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 MVPbkContactOperation* CContactStore::CreateFindOperationL(
       
   674     const TDesC&            /* aSearchString */,
       
   675     const MVPbkFieldTypeList& /* aFieldTypes */,
       
   676     MVPbkContactFindObserver&   /* aObserver */ )
       
   677     {
       
   678     return NULL;
       
   679     }
       
   680 
       
   681 MVPbkContactOperation* CContactStore::CreateFindOperationL(
       
   682                 const MDesC16Array& aSearchStrings, 
       
   683                 const MVPbkFieldTypeList& aFieldTypes, 
       
   684                 MVPbkContactFindFromStoresObserver& aObserver, 
       
   685                 const TCallBack& aWordParserCallBack)
       
   686     {
       
   687     return NULL;
       
   688     }
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CContactStore::CreateCompressStoresOperationL
       
   692 // -----------------------------------------------------------------------------
       
   693 //
       
   694 MVPbkContactOperation* CContactStore::CreateCompressStoresOperationL(
       
   695     MVPbkBatchOperationObserver& /*aObserver*/
       
   696 )
       
   697     {
       
   698     // Remote store
       
   699     return NULL;
       
   700     }
       
   701 
       
   702 // -----------------------------------------------------------------------------
       
   703 //                      MVPbkContactStore implementation
       
   704 // -----------------------------------------------------------------------------
       
   705 // CContactStore::StoreProperties
       
   706 // Returns store properties.
       
   707 // -----------------------------------------------------------------------------
       
   708 //
       
   709 const MVPbkContactStoreProperties& CContactStore::StoreProperties() const
       
   710     {
       
   711     return *iProperties;
       
   712     }
       
   713 
       
   714 // -----------------------------------------------------------------------------
       
   715 // CContactStore::OpenL
       
   716 // Opens this store asynchronously.
       
   717 // -----------------------------------------------------------------------------
       
   718 //
       
   719 void CContactStore::OpenL(MVPbkContactStoreObserver& aObserver)
       
   720     {
       
   721     // Add observers
       
   722     AddObserverL(aObserver);
       
   723 
       
   724     // State is idle
       
   725     if (iState == EIdle)
       
   726         {
       
   727         // Start initializing
       
   728         iState = EInitializing;
       
   729         // Clear for new notifier
       
   730         if (iIdle)
       
   731             {
       
   732             // Cancel pending operation
       
   733             iIdle->Cancel();
       
   734             delete iIdle;
       
   735             iIdle = NULL;
       
   736             }
       
   737         // Create initializer
       
   738         iIdle = CIdle::NewL(CActive::EPriorityStandard);
       
   739         // Initialized notifier
       
   740         TCallBack callback(LDAPStoreInitializeL,this);
       
   741         // Start
       
   742         iIdle->Start(callback);
       
   743         }
       
   744     else
       
   745         {
       
   746         // Still active, observer will be notified
       
   747         if (iIdle && iIdle->IsActive())
       
   748             return;
       
   749 
       
   750         // Clear for new notifier
       
   751         if (iIdle)
       
   752             {
       
   753             // Cancel pending operation
       
   754             iIdle->Cancel();
       
   755             delete iIdle;
       
   756             iIdle = NULL;
       
   757             }
       
   758 
       
   759         // Create store ready notifier
       
   760         iIdle = CIdle::NewL(CActive::EPriorityStandard);
       
   761         // Store ready notifier
       
   762         TCallBack callback(LDAPStoreReady,this);
       
   763         // Start
       
   764         iIdle->Start(callback);
       
   765         }
       
   766     }
       
   767 
       
   768 // -----------------------------------------------------------------------------
       
   769 // CContactStore::ReplaceL
       
   770 // Replaces an existing store and opens it asynchronously.
       
   771 // -----------------------------------------------------------------------------
       
   772 //
       
   773 void CContactStore::ReplaceL(MVPbkContactStoreObserver& aObserver)
       
   774     {
       
   775     OpenL(aObserver);
       
   776     }
       
   777 // -----------------------------------------------------------------------------
       
   778 // CContactStore::Close
       
   779 // Closes this contact store from a single observer.
       
   780 // -----------------------------------------------------------------------------
       
   781 //
       
   782 void CContactStore::Close(MVPbkContactStoreObserver& aObserver)
       
   783     {
       
   784     // Remove observer
       
   785     RemoveObserver(aObserver);
       
   786     // Last one switch the lights off
       
   787     if (iStoreObservers.Count() == 0)
       
   788         {
       
   789         // Close connection
       
   790         if (iDirectory && iDirectory->IsConnected())
       
   791             {
       
   792             iDirectory->Shutdown();
       
   793             }
       
   794         iState = EClosed;
       
   795         }
       
   796     }
       
   797 
       
   798 // -----------------------------------------------------------------------------
       
   799 // CContactStore::CreateNewContactLC
       
   800 // Creates new contact associated to this store.
       
   801 // -----------------------------------------------------------------------------
       
   802 //
       
   803 MVPbkStoreContact* CContactStore::CreateNewContactLC()
       
   804     {
       
   805     // Read only
       
   806     return NULL;
       
   807     }
       
   808 
       
   809 // -----------------------------------------------------------------------------
       
   810 // CContactStore::CreateNewContactGroupLC
       
   811 // Creates contact group associated to this store.
       
   812 // -----------------------------------------------------------------------------
       
   813 //
       
   814 MVPbkContactGroup* CContactStore::CreateNewContactGroupLC()
       
   815     {
       
   816     // No groups
       
   817     return NULL;
       
   818     }
       
   819 
       
   820 // -----------------------------------------------------------------------------
       
   821 // CContactStore::CreateViewLC
       
   822 // Creates contact view.
       
   823 // -----------------------------------------------------------------------------
       
   824 //
       
   825 MVPbkContactView* CContactStore::CreateViewLC(
       
   826     const CVPbkContactViewDefinition& aViewDefinition,
       
   827     MVPbkContactViewObserver& aObserver,
       
   828     const MVPbkFieldTypeList& aSortOrder
       
   829 )
       
   830     {
       
   831     // View type
       
   832     TVPbkContactViewType type = aViewDefinition.Type();
       
   833     // Contact view
       
   834     MVPbkContactView* vp = NULL;
       
   835     // Folding view
       
   836     if (type == EVPbkFoldingView &&
       
   837         aViewDefinition.FlagIsOn(EVPbkContactViewFolding))
       
   838         {
       
   839         vp = CContactView::NewLC(aObserver,*this,aSortOrder,type);
       
   840         }
       
   841     else
       
   842         {
       
   843         // Clear old results
       
   844         iContacts.ResetAndDestroy();
       
   845 
       
   846         // Finder
       
   847         CLDAPFinderUI& finder = iStoreDomain.FinderUI();
       
   848         finder.ExecuteL(*iDirectory);
       
   849         iState = ESearching;
       
   850 
       
   851         // Contact view
       
   852         type = EVPbkContactsView;
       
   853         vp = CContactView::NewLC(aObserver,*this,aSortOrder,type);
       
   854         }
       
   855     return vp;
       
   856     }
       
   857 
       
   858 // -----------------------------------------------------------------------------
       
   859 // CContactStore::ContactGroupsLC
       
   860 // Returns contact groups from this store.
       
   861 // -----------------------------------------------------------------------------
       
   862 //    
       
   863 MVPbkContactLinkArray* CContactStore::ContactGroupsLC() const
       
   864     {
       
   865     // No groups
       
   866     return NULL;
       
   867     }
       
   868 
       
   869 // -----------------------------------------------------------------------------
       
   870 // CContactStore::StoreInfo
       
   871 // -----------------------------------------------------------------------------
       
   872 //
       
   873 const MVPbkContactStoreInfo& CContactStore::StoreInfo() const
       
   874     {
       
   875     return *iStoreInfo;
       
   876     }
       
   877 
       
   878 // -----------------------------------------------------------------------------
       
   879 // CContactStore::CreateLinkFromInternalsLC
       
   880 // Creates contact link from packed stream.
       
   881 // -----------------------------------------------------------------------------
       
   882 //
       
   883 MVPbkContactLink* CContactStore::CreateLinkFromInternalsLC(
       
   884     RReadStream& aStream) const
       
   885     {
       
   886     // Read index and type id
       
   887     TInt index = aStream.ReadInt32L();
       
   888     TInt type  = aStream.ReadInt32L();
       
   889     // New contact link
       
   890     return CContactLink::NewLC(const_cast<CContactStore&>(*this),index,type);
       
   891     }
       
   892 
       
   893 // -----------------------------------------------------------------------------
       
   894 //                      MDirectoryObserver implementation
       
   895 // -----------------------------------------------------------------------------
       
   896 // CContactStore::ActionDoneL
       
   897 // This method is called when action ends
       
   898 // -----------------------------------------------------------------------------
       
   899 //
       
   900 void CContactStore::ActionDoneL(
       
   901     LDAPEngine::CDirectory& /* aDirectory */,
       
   902     LDAPEngine::TActionType aAction,
       
   903     TInt aStatus, TPtrC8 // aErrorMsg
       
   904 )
       
   905     {
       
   906     // Action was successful
       
   907     if (aStatus == KErrNone)
       
   908         {
       
   909         // Connected
       
   910         if (aAction == LDAPEngine::EConnect)
       
   911             {
       
   912             iState = EOpened;
       
   913             }
       
   914         else
       
   915         // Secured connection
       
   916         if (aAction == LDAPEngine::ESecureConnection)
       
   917             {
       
   918             }
       
   919         else
       
   920         // Authenticated
       
   921         if (aAction == LDAPEngine::EAuthenticate)
       
   922             {
       
   923             }
       
   924         else
       
   925         // Search done
       
   926         if (aAction == LDAPEngine::ESearchAction)
       
   927             {
       
   928             // Contacts from directory
       
   929             RetrieveContactsL();
       
   930             // Search done
       
   931             iState = ERetrieved;
       
   932             }
       
   933         else
       
   934         // Logout
       
   935         if (aAction == LDAPEngine::ELogout)
       
   936             {
       
   937             }
       
   938         else
       
   939         // Disconnect, shutdown
       
   940         if (aAction == LDAPEngine::EDisconnect)
       
   941             {
       
   942             iState = EIdle;
       
   943             }
       
   944         }
       
   945     else
       
   946 
       
   947     // Limits exceeded warnings
       
   948     if (aStatus == LDAPEngine::ETimeLimitExceeded ||
       
   949         aStatus == LDAPEngine::ESizeLimitExceeded)
       
   950         {
       
   951         // Search done
       
   952         if (aAction == LDAPEngine::ESearchAction)
       
   953             {
       
   954             // Contacts from directory
       
   955             RetrieveContactsL();
       
   956             // Search done
       
   957             iState = ERetrieved;
       
   958             }
       
   959         }
       
   960     }
       
   961 
       
   962 // -----------------------------------------------------------------------------
       
   963 // CContactStore::ConnectionStateChangedL
       
   964 // This is notified when directory connection state changes.
       
   965 // -----------------------------------------------------------------------------
       
   966 //
       
   967 void CContactStore::ConnectionStateChangedL(
       
   968     LDAPEngine::CDirectory& /* aDirectory */,
       
   969     LDAPEngine::TConnectionState aState
       
   970 )
       
   971     {
       
   972     // According state
       
   973     switch (aState)
       
   974         {
       
   975         case LDAPEngine::EIdle:
       
   976             break;
       
   977 
       
   978         // Directory configured
       
   979         case LDAPEngine::EConfigured:
       
   980             // Previous state was
       
   981             if (iState == EIdle || iState == EInitializing)
       
   982                 {
       
   983                 // New state
       
   984                 iState = EInitialized;
       
   985                 // Notify store ready
       
   986                 StoreReady();
       
   987                 }
       
   988             break;
       
   989 
       
   990         // Intermediate connecting states are irrelevant
       
   991         case LDAPEngine::ELookingUp:
       
   992         case LDAPEngine::EConnecting:
       
   993         case LDAPEngine::EConnected:
       
   994         case LDAPEngine::ESecuring:
       
   995         case LDAPEngine::ESecured:
       
   996             break;
       
   997 
       
   998         // Authentication states
       
   999         case LDAPEngine::EAuthenticating:
       
  1000             break;
       
  1001         case LDAPEngine::EAuthenticated:
       
  1002             break;
       
  1003 
       
  1004         case LDAPEngine::ESending:
       
  1005             break;
       
  1006         case LDAPEngine::ESent:
       
  1007             break;
       
  1008         case LDAPEngine::EReceiving:
       
  1009             iState = ERetrieving;
       
  1010             break;
       
  1011         case LDAPEngine::EReceived:
       
  1012             break;
       
  1013         case LDAPEngine::EWaiting:
       
  1014             break;
       
  1015 
       
  1016         case LDAPEngine::ESearching:
       
  1017             iState = ESearching;
       
  1018             break;
       
  1019         case LDAPEngine::ESearchDone:
       
  1020             break;
       
  1021 
       
  1022         // Directory is closing down
       
  1023         case LDAPEngine::EUnbinding:
       
  1024         case LDAPEngine::EUnbound:
       
  1025         case LDAPEngine::EClosing:
       
  1026             iState = EClosing;
       
  1027             break;
       
  1028 
       
  1029         case LDAPEngine::EClosed:
       
  1030             iState = EClosed;
       
  1031             break;
       
  1032 
       
  1033         case LDAPEngine::EShutdown:
       
  1034             iState = EIdle;
       
  1035             break;
       
  1036 
       
  1037         default:
       
  1038             break;
       
  1039         } // End of switch state
       
  1040     }
       
  1041 
       
  1042 }  // End of namespace LDAPStore
       
  1043 // -----------------------------------------------------------------------------
       
  1044 //  End of File
       
  1045 // -----------------------------------------------------------------------------