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