phonebookui/Phonebook2/remotecontactlookup/contactactionservice/src/cfsccontactlinkset.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2008 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 of the class CFscContactLinkSet.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCUDES
       
    20 #include "emailtrace.h"
       
    21 #include <CVPbkContactManager.h>
       
    22 #include <MVPbkContactOperationBase.h>
       
    23 #include "mfsccontactlinkiterator.h"
       
    24 #include "mfsccontactsetobserver.h"
       
    25 #include <MVPbkStoreContact.h>
       
    26 #include <MVPbkContactLinkArray.h>
       
    27 
       
    28 #include "cfsccontactlinkset.h"
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // Two-phased constructor.
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CFscContactLinkSet* CFscContactLinkSet::NewL( 
       
    37     CVPbkContactManager& aVPbkContactManager,
       
    38     MFscContactLinkIterator* aIterator )
       
    39     {
       
    40     FUNC_LOG;
       
    41 
       
    42     CFscContactLinkSet* self = 
       
    43         new ( ELeave ) CFscContactLinkSet( aVPbkContactManager );
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL( aIterator );
       
    46     CleanupStack::Pop( self );
       
    47         
       
    48     return self;
       
    49     }
       
    50     
       
    51 // ---------------------------------------------------------------------------
       
    52 // Destructor.
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CFscContactLinkSet::~CFscContactLinkSet()
       
    56     {
       
    57     FUNC_LOG;
       
    58     delete iCurrentContact;
       
    59     delete iContactLinkArray;
       
    60     delete iVPbkOperationNextContact;
       
    61     delete iVPbkOperationNextGroup;
       
    62     delete iVPbkOperationGetGroupContact;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Contact count.
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TInt CFscContactLinkSet::ContactCount() const
       
    70     {
       
    71     FUNC_LOG;
       
    72     return iIterator->ContactCount();
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // Checks if iterator has more contacts.
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 TBool CFscContactLinkSet::HasNextContact() const
       
    80     {
       
    81     FUNC_LOG;
       
    82     return iIterator->HasNextContact();
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // Sets the iterator to point to the first contact in the list.
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CFscContactLinkSet::SetToFirstContact()
       
    90     {
       
    91     FUNC_LOG;
       
    92     iIterator->SetToFirstContact();
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // Asynchronous operation for retrieving store contact for contact.
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CFscContactLinkSet::NextContactL( MFscContactSetObserver* aObserver )
       
   100     {
       
   101     FUNC_LOG;
       
   102     MVPbkContactLink* contactLink = iIterator->NextContactL();
       
   103     
       
   104     iObserver = aObserver;
       
   105     
       
   106     // async call - result in VPbkSingleContactOperationComplete()
       
   107     iVPbkOperationNextContact = 
       
   108             iVPbkContactManager.RetrieveContactL( *contactLink, *this );
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // Used for retrieving link for contact.
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 MVPbkContactLink* CFscContactLinkSet::NextContactLinkL()
       
   116     {
       
   117     FUNC_LOG;
       
   118     return iIterator->NextContactL();
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // Used for canceling asynchronous NextContactL operation.
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 void CFscContactLinkSet::CancelNextContactL()
       
   126     {
       
   127     FUNC_LOG;
       
   128     CancelGetGroupContactL();
       
   129     if ( iVPbkOperationNextContact )
       
   130         {
       
   131         delete iVPbkOperationNextContact;
       
   132         iVPbkOperationNextContact = NULL;
       
   133         }
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // Group count.
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 TInt CFscContactLinkSet::GroupCount() const
       
   141     {
       
   142     FUNC_LOG;
       
   143     return iIterator->GroupCount();
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // Checks if iterator has more groups.
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 TBool CFscContactLinkSet::HasNextGroup() const
       
   151     {
       
   152     FUNC_LOG;
       
   153     return iIterator->HasNextGroup();
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // Sets the iterator to point to the first group in the list.
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 void CFscContactLinkSet::SetToFirstGroup()
       
   161     {
       
   162     FUNC_LOG;
       
   163     iIterator->SetToFirstGroup();
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // Asynchronous operation for retrieving store contact for group.
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CFscContactLinkSet::NextGroupL( MFscContactSetObserver* aObserver )
       
   171     {
       
   172     FUNC_LOG;
       
   173     MVPbkContactLink* groupLink = iIterator->NextGroupL();
       
   174         
       
   175     iObserver = aObserver;
       
   176     
       
   177     // async call - result in VPbkSingleContactOperationComplete()
       
   178     iVPbkOperationNextGroup = 
       
   179             iVPbkContactManager.RetrieveContactL( *groupLink, *this );
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // Used for retrieving link for group.
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 MVPbkContactLink* CFscContactLinkSet::NextGroupLinkL()
       
   187     {
       
   188     FUNC_LOG;
       
   189     return iIterator->NextGroupL();
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // Used for canceling asynchronous NextGroupL operation.
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 void CFscContactLinkSet::CancelNextGroupL()
       
   197     {
       
   198     FUNC_LOG;
       
   199     CancelGetGroupContactL();
       
   200     if ( iVPbkOperationNextGroup )
       
   201         {
       
   202         delete iVPbkOperationNextGroup;
       
   203         iVPbkOperationNextGroup = NULL;
       
   204         }
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // From MVPbkSingleContactOperationObserver.
       
   209 // Called when the operation is completed.
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CFscContactLinkSet::VPbkSingleContactOperationComplete(
       
   213     MVPbkContactOperationBase& aOperation,
       
   214     MVPbkStoreContact* aContact )
       
   215     {
       
   216     FUNC_LOG;
       
   217     if ( iVPbkOperationNextContact == &aOperation )
       
   218         {
       
   219         delete iCurrentContact;
       
   220         iCurrentContact = aContact;
       
   221         delete iVPbkOperationNextContact;
       
   222         iVPbkOperationNextContact = NULL;
       
   223         iObserver->NextContactComplete( iCurrentContact );
       
   224         }
       
   225     else if ( iVPbkOperationNextGroup == &aOperation )
       
   226         {
       
   227         delete iCurrentContact;
       
   228         iCurrentContact = aContact;
       
   229         delete iVPbkOperationNextGroup;
       
   230         iVPbkOperationNextGroup = NULL;
       
   231         iObserver->NextGroupComplete( iCurrentContact );
       
   232         }
       
   233     else if ( iVPbkOperationGetGroupContact == &aOperation )
       
   234         {
       
   235         delete iVPbkOperationGetGroupContact;
       
   236         iVPbkOperationGetGroupContact = NULL;
       
   237         
       
   238         delete iContactLinkArray;
       
   239         iContactLinkArray = NULL;
       
   240         
       
   241         iObserver->GetGroupContactComplete( aContact );
       
   242         }
       
   243     else
       
   244         {
       
   245         //User::Leave( KErrArgument );
       
   246         }
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // From MVPbkSingleContactOperationObserver.
       
   251 // Called if the operation fails.
       
   252 // ---------------------------------------------------------------------------
       
   253 //
       
   254 void CFscContactLinkSet::VPbkSingleContactOperationFailed(
       
   255     MVPbkContactOperationBase& aOperation, TInt aError )
       
   256     {
       
   257     FUNC_LOG;
       
   258     if ( iVPbkOperationNextContact == &aOperation )
       
   259         {
       
   260         delete iVPbkOperationNextContact;
       
   261         iVPbkOperationNextContact = NULL;
       
   262         iObserver->NextContactFailed( aError );
       
   263         }
       
   264     else if ( iVPbkOperationNextGroup == &aOperation )
       
   265         {
       
   266         delete iVPbkOperationNextGroup;
       
   267         iVPbkOperationNextGroup = NULL;
       
   268         iObserver->NextGroupFailed( aError );
       
   269         }
       
   270     else if ( iVPbkOperationGetGroupContact == &aOperation )
       
   271         {
       
   272         delete iVPbkOperationGetGroupContact;
       
   273         iVPbkOperationGetGroupContact = NULL;
       
   274         
       
   275         delete iContactLinkArray;
       
   276         iContactLinkArray = NULL;
       
   277         
       
   278         iObserver->GetGroupContactFailed( aError );
       
   279         }
       
   280     else
       
   281         {
       
   282         //User::Leave( KErrArgument );
       
   283         }
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // Constructor.
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 CFscContactLinkSet::CFscContactLinkSet( 
       
   291     CVPbkContactManager& aVPbkContactManager )
       
   292     : CFscContactSet( aVPbkContactManager )
       
   293     {
       
   294     FUNC_LOG;
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // Second phase constructor.
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 void CFscContactLinkSet::ConstructL( MFscContactLinkIterator* aIterator )
       
   302     {
       
   303     FUNC_LOG;
       
   304     iIterator = aIterator;        
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // Used for canceling asynchronous GetGroupContactL operation.
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 void CFscContactLinkSet::CancelGetGroupContactL()
       
   312     {
       
   313     FUNC_LOG;
       
   314     if ( iVPbkOperationGetGroupContact )
       
   315         {
       
   316         delete iVPbkOperationGetGroupContact;
       
   317         iVPbkOperationGetGroupContact = NULL;
       
   318         
       
   319         delete iContactLinkArray;
       
   320         iContactLinkArray = NULL;
       
   321         }
       
   322     }
       
   323