phoneengine/PhoneCntFinder/ContactService/src/CPhCntSingleItemFetchService.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 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:  Service for fetching single contact field.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <featmgr.h>         // Feature Manager
       
    20 #include "CPhCntSingleItemFetchService.h"
       
    21 #include "cphcntphonebookservices.h"
       
    22 #include "tphcntservicerequestparamfactory.h"
       
    23 #include "cphcntcontactid.h"
       
    24 #include "CPhCntContact.h"
       
    25 
       
    26    
       
    27 // ---------------------------------------------------------------------------
       
    28 // Static constructor
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CPhCntSelectionImpl* CPhCntSelectionImpl::NewL(
       
    32     const TDesC& aNumber, 
       
    33     const CPhCntContactId& aContactId )
       
    34     {
       
    35     CPhCntSelectionImpl* self = new( ELeave )CPhCntSelectionImpl();
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL( aNumber, aContactId );
       
    38     CleanupStack::Pop( self );
       
    39     return self;
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // Constructor
       
    44 // ---------------------------------------------------------------------------
       
    45 //    
       
    46 CPhCntSelectionImpl::CPhCntSelectionImpl()
       
    47     {
       
    48     }
       
    49     
       
    50 // ---------------------------------------------------------------------------
       
    51 // Second-phase constructor
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 void CPhCntSelectionImpl::ConstructL(
       
    55     const TDesC& aNumber, 
       
    56     const CPhCntContactId& aContactId)
       
    57     {
       
    58     iNumber = aNumber.AllocL();
       
    59     iContactId = aContactId.CloneL();
       
    60     FeatureManager::InitializeLibL();
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Destructor
       
    65 // ---------------------------------------------------------------------------
       
    66 // 
       
    67 CPhCntSelectionImpl::~CPhCntSelectionImpl()
       
    68     {
       
    69     delete iNumber;
       
    70     delete iContactId;
       
    71     FeatureManager::UnInitializeLib();
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Returns number
       
    76 // ---------------------------------------------------------------------------
       
    77 //     
       
    78 const TDesC& CPhCntSelectionImpl::Number() const
       
    79     {
       
    80     return *iNumber;
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // Returns contact id
       
    85 // ---------------------------------------------------------------------------
       
    86 // 
       
    87 const CPhCntContactId& CPhCntSelectionImpl::ContactId() const
       
    88     {
       
    89     return *iContactId;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // Static constructor
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 CPhCntSingleItemFetchService* CPhCntSingleItemFetchService::NewL(
       
    97     MPhCntContactStores& aContactStores,
       
    98     MPhCntContactManager& aContactManager )
       
    99     {
       
   100     CPhCntSingleItemFetchService* self = 
       
   101         new( ELeave )CPhCntSingleItemFetchService();
       
   102     CleanupStack::PushL( self );
       
   103     self->ConstructL( 
       
   104         aContactStores, aContactManager );
       
   105     CleanupStack::Pop( self );
       
   106     return self;    
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Destructor
       
   111 // ---------------------------------------------------------------------------
       
   112 //    
       
   113 CPhCntSingleItemFetchService::~CPhCntSingleItemFetchService() 
       
   114     {
       
   115     delete iParamFactory;
       
   116     delete iServices;
       
   117     if( iDestroyed ) 
       
   118         {
       
   119         *iDestroyed = ETrue;
       
   120         }
       
   121     }
       
   122    
       
   123 // ---------------------------------------------------------------------------
       
   124 // From CPhCntSingleItemFetch
       
   125 // Fetches phone number
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TInt CPhCntSingleItemFetchService::FetchLD( 
       
   129     TFetchParams& aParams ) 
       
   130     {
       
   131     TBool destroyed = EFalse;
       
   132     iDestroyed = &destroyed;
       
   133     HBufC* number = NULL;
       
   134     TInt err = KErrNone;
       
   135     if( aParams.iType == CPhCntSingleItemFetch::EFetchDtmf )
       
   136         {
       
   137         TRAP( err, 
       
   138             iServices->GetUserSelectedDtmfNumberL( 
       
   139                 aParams.iContactId, number ) );
       
   140         }
       
   141     else if( aParams.iType == CPhCntSingleItemFetch::EFetchNewCall )
       
   142         {
       
   143         TRAP( err, 
       
   144             iServices->GetUserSelectedPhoneNumberL( 
       
   145                 aParams.iContactId, number ) );
       
   146         }
       
   147     else if( aParams.iType == CPhCntSingleItemFetch::EFetchNewPSCall && 
       
   148              FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) )
       
   149         {
       
   150         TRAP( err, 
       
   151             iServices->GetUserSelectedVoIPAddressL( 
       
   152                 aParams.iContactId, number ) );
       
   153         }
       
   154     else
       
   155         {
       
   156         User::Leave( KErrNotSupported );
       
   157         }
       
   158     // Do not touch member variables after this, because service is canceled
       
   159     // by deleting this instance. Deletion causes above request to complete and
       
   160     // execution will be here after deletion.
       
   161         
       
   162     TInt error = KErrNone;
       
   163     if( !err )
       
   164         {
       
   165         error = SetFetchParams( aParams, *number );
       
   166         }
       
   167     else if( err == KErrCancel )
       
   168         {
       
   169         error = KErrCancel;
       
   170         }
       
   171     else 
       
   172         {
       
   173         if( !destroyed )
       
   174             {
       
   175             iDestroyed = NULL;
       
   176             delete this;
       
   177             }
       
   178         User::Leave( err );     
       
   179         }
       
   180     delete number;
       
   181     if( !destroyed )
       
   182         {
       
   183         iDestroyed = NULL;
       
   184         delete this;
       
   185         }
       
   186     return error;
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // From CPhCntSingleItemFetch
       
   191 // Fetches phone number
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 TInt CPhCntSingleItemFetchService::FetchPhoneNumberLD( 
       
   195     const TDesC8& aContactLink,
       
   196     const CPhCntSingleItemFetch::TCallType aCallType,
       
   197     HBufC*& aNumber,
       
   198     HBufC8*& aFieldLink ) 
       
   199     {
       
   200     TBool destroyed = EFalse;
       
   201     iDestroyed = &destroyed;    
       
   202     TInt err = KErrNone;
       
   203         
       
   204     TRAP( err, 
       
   205     	iServices->GetPhoneNumberL( aContactLink, aCallType, aNumber, aFieldLink ) 
       
   206     	);                        
       
   207 
       
   208     // Do not touch member variables after this, because service is canceled
       
   209     // by deleting this instance. Deletion causes above request to complete and
       
   210     // execution will be here after deletion.
       
   211     
       
   212     TInt error = KErrNone;    
       
   213     if( err )
       
   214     	{
       
   215     	delete aNumber;
       
   216     	aNumber = NULL;
       
   217     	delete aFieldLink;
       
   218     	aFieldLink = NULL;
       
   219 	    if( err == KErrCancel )
       
   220 	        {
       
   221 	        error = KErrCancel;
       
   222 	        }
       
   223 	    else 
       
   224 	        {
       
   225 	        if( !destroyed )
       
   226 	            {
       
   227 	            iDestroyed = NULL;
       
   228 	            delete this;
       
   229 	            }
       
   230 	        User::Leave( err );     
       
   231 	        }	
       
   232     	}
       
   233                     
       
   234     if( !destroyed )
       
   235         {
       
   236         iDestroyed = NULL;
       
   237         delete this;
       
   238         }
       
   239     return error;
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // From CPhCntSingleItemFetch
       
   244 // Fetches phone number
       
   245 // ---------------------------------------------------------------------------
       
   246 //    
       
   247 CPhCntSelection* CPhCntSingleItemFetchService::SelectPhoneNumberLD()
       
   248     {
       
   249     TBool destroyed = EFalse;
       
   250     iDestroyed = &destroyed;    
       
   251     CPhCntSelectionImpl* selection = NULL;
       
   252 
       
   253     CPhCntContact* contact = NULL;
       
   254     TRAPD( err, 
       
   255         MPhCntServiceRequestParam* param = 
       
   256             iParamFactory->CreateGetUserSelectedPhoneNumberLC();
       
   257         contact = iServices->GetUserSelectedContactLC( *param );
       
   258         CleanupStack::Pop( contact );
       
   259         CleanupStack::PopAndDestroy( 1 ); // param
       
   260         );
       
   261     if( !destroyed )
       
   262         {
       
   263         iDestroyed = NULL;
       
   264         delete this;
       
   265         }
       
   266         
       
   267     if( !err )
       
   268         {
       
   269         CleanupStack::PushL( contact );
       
   270         selection = CPhCntSelectionImpl::NewL( 
       
   271             contact->Number(), *contact->ContactId() );
       
   272         CleanupStack::PopAndDestroy( contact );
       
   273         }
       
   274     else
       
   275         {
       
   276         // If the request is canceled then do not leave, because
       
   277         // of agreement with clients.
       
   278         if( err != KErrCancel )
       
   279             {
       
   280             User::Leave( err );    
       
   281             }
       
   282         }
       
   283         
       
   284     
       
   285     return selection;
       
   286     }
       
   287 // ---------------------------------------------------------------------------
       
   288 // Sets possible error values and return values.
       
   289 // ---------------------------------------------------------------------------
       
   290 // 
       
   291 TInt CPhCntSingleItemFetchService::SetFetchParams( 
       
   292     TFetchParams& aParams,
       
   293     const TDesC& aReceivedPhoneNumber  ) const
       
   294     {
       
   295     TInt errorValue( KErrNone );
       
   296     
       
   297     if( aReceivedPhoneNumber.Length() >= aParams.iString->MaxLength() ) 
       
   298         {
       
   299         errorValue = KErrOverflow;
       
   300         }
       
   301     
       
   302     if( errorValue == KErrNone ) 
       
   303         {
       
   304         aParams.iString->Zero();
       
   305         aParams.iString->Copy( aReceivedPhoneNumber );
       
   306         }
       
   307     
       
   308     
       
   309     return errorValue;
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // Constructor
       
   314 // ---------------------------------------------------------------------------
       
   315 //     
       
   316 CPhCntSingleItemFetchService::CPhCntSingleItemFetchService()
       
   317     {
       
   318     }
       
   319     
       
   320 // ---------------------------------------------------------------------------
       
   321 // Seconds phase constructor
       
   322 // ---------------------------------------------------------------------------
       
   323 //     
       
   324 void CPhCntSingleItemFetchService::ConstructL( 
       
   325     MPhCntContactStores& aContactStores,
       
   326     MPhCntContactManager& aContactManager )
       
   327     {
       
   328     iParamFactory = CPhCntServiceRequestParamFactory::NewL( aContactManager );
       
   329     iServices = CPhCntPhonebookServices::NewL( 
       
   330         aContactStores, aContactManager );
       
   331     }
       
   332 
       
   333