messagingappbase/msgavkon/muiu_internal/servicesinternal/src/MuiuContactService.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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:   Calls voice call or VoIP call to either of addresses provided. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <eikenv.h>
       
    21 #include <coemain.h>
       
    22 #include <ItemFinder.h>
       
    23 #include <msgvoipextension.h>
       
    24 #include <commonphoneparser.h>      // Common phone number validity checker
       
    25 
       
    26 #include "MuiuContactService.h"
       
    27 #include "MuiuContactAddressMatcher.h"
       
    28     
       
    29 // ---------------------------------------------------------
       
    30 // CMuiuContactService::NewL
       
    31 // ---------------------------------------------------------
       
    32 EXPORT_C CMuiuContactService* CMuiuContactService::NewL( 
       
    33         CEikonEnv&          aEnv,
       
    34         CMsgVoIPExtension*  aVoipExtension ) 
       
    35     {
       
    36     CMuiuContactService* self =
       
    37         new( ELeave ) CMuiuContactService( aEnv, aVoipExtension );
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // CMuiuContactService::CMuiuContactService
       
    47 // ---------------------------------------------------------
       
    48 CMuiuContactService::CMuiuContactService(   CEikonEnv&          aEnv,
       
    49                                             CMsgVoIPExtension*  aVoipExtension ):
       
    50     iEikEnv( aEnv ),
       
    51     iVoipExtension( aVoipExtension )
       
    52     {
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------
       
    57 // CMuiuContactService::ConstructL
       
    58 // ---------------------------------------------------------
       
    59 void CMuiuContactService::ConstructL()
       
    60     {
       
    61     if ( !iVoipExtension )
       
    62         {
       
    63         iVoipExtension = CMsgVoIPExtension::NewL( );
       
    64         }
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // CMuiuContactService::~CMuiuContactService
       
    69 // ---------------------------------------------------------
       
    70 EXPORT_C CMuiuContactService::~CMuiuContactService()
       
    71     {
       
    72     delete iVoipExtension;
       
    73     delete iContactAddressMatcher;
       
    74     delete iMatchAddress;
       
    75     delete iMatchName;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // CMuiuContactService::PreferredCallTypeL
       
    80 // ---------------------------------------------------------
       
    81 EXPORT_C CMuiuContactService::TMuiuPreferredCallType CMuiuContactService::PreferredCallTypeL() const
       
    82     {
       
    83     CMuiuContactService::TMuiuPreferredCallType preferredCallType( EMuiuCallTypeVoice );
       
    84     if (    iVoipExtension
       
    85         &&  iVoipExtension->IsPreferredTelephonyVoIP( )
       
    86         &&  iVoipExtension->VoIPProfilesExistL() )
       
    87         {
       
    88         preferredCallType = EMuiuCallTypeVoip;
       
    89         }
       
    90     return preferredCallType;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // CMuiuContactService::SetAddress
       
    95 // ---------------------------------------------------------
       
    96 EXPORT_C void CMuiuContactService::SetAddress( const TDesC& aAddress )
       
    97     {
       
    98     if ( iWait.IsStarted( ) )
       
    99         {
       
   100         // if searching, changes are not allowed, which may affect call handling
       
   101         // iPrimaryAddress may be used after search completes
       
   102         return;
       
   103         }
       
   104 
       
   105     iPrimaryAddress.Set( aAddress );
       
   106     delete iMatchAddress;
       
   107     iMatchAddress = NULL;
       
   108     delete iMatchName;
       
   109     iMatchName = NULL;
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // CMuiuContactService::SetName
       
   114 // ---------------------------------------------------------
       
   115 EXPORT_C void CMuiuContactService::SetName( const TDesC& aName )
       
   116     {
       
   117     if ( iWait.IsStarted( ) )
       
   118         {
       
   119         // if searching, changes are not allowed, which may affect call handling
       
   120         // iPrimaryName may be used after search completes
       
   121         return;
       
   122         }
       
   123     iPrimaryName.Set( aName );
       
   124     delete iMatchAddress;
       
   125     iMatchAddress = NULL;
       
   126     delete iMatchName;
       
   127     iMatchName = NULL;
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------
       
   131 // CMuiuContactService::CallL
       
   132 // ---------------------------------------------------------
       
   133 EXPORT_C TBool CMuiuContactService::CallL( )
       
   134     {
       
   135     return CallL( KNullDesC );
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // CMuiuContactService::CallL
       
   140 // ---------------------------------------------------------
       
   141 EXPORT_C TBool CMuiuContactService::CallL( const TDesC& aSecondaryAddress )
       
   142     {
       
   143     if ( iWait.IsStarted( ) )
       
   144         {
       
   145         // if searching, changes are not allowed, which may affect call handling
       
   146         User::Leave( KErrNotSupported );
       
   147         }
       
   148 
       
   149     TBool ret = EFalse;
       
   150     // Primary address data
       
   151     TPtrC primaryAddress( KNullDesC );
       
   152     TPtrC primaryName( KNullDesC );
       
   153     TMuiuAddressType primaryAddressType = MsvUiServiceUtilitiesInternal::ResolveAddressTypeL( 
       
   154               iPrimaryAddress ); 
       
   155     
       
   156     // resolve type of secondary (find item) address
       
   157     iSecondaryAddress.Set( aSecondaryAddress );
       
   158     TMuiuAddressType secondaryAddressType = MsvUiServiceUtilitiesInternal::ResolveAddressTypeL( 
       
   159         iSecondaryAddress ); 
       
   160 
       
   161     // Get preferred call type    
       
   162     CMuiuContactService::TMuiuPreferredCallType preferredCallType = PreferredCallTypeL( );
       
   163     if ( preferredCallType == EMuiuCallTypeVoice ) 
       
   164         {
       
   165         TMuiuAddressType foundAddressType = MsvUiServiceUtilitiesInternal::ResolveAddressTypeL( 
       
   166               FoundContactAddressL() ); 
       
   167 
       
   168         if (    primaryAddressType == EMuiuAddressTypeEmail
       
   169             &&  foundAddressType !=  EMuiuAddressTypePhoneNumber )
       
   170             {
       
   171             // Search to phonebook must be done, if sender's address is email and
       
   172             // found address is not phone number
       
   173             ret = ETrue;
       
   174             if ( !iContactAddressMatcher )
       
   175                 {
       
   176                 iContactAddressMatcher = CMuiuContactAddressMatcher::NewL( iEikEnv ); 
       
   177                 }
       
   178             iContactAddressMatcher->FindContactL(   iPrimaryAddress,
       
   179                                                     TCallBack( MatchDone, this) );
       
   180             iWait.Start( );
       
   181 
       
   182             // get results
       
   183             delete iMatchAddress;
       
   184             iMatchAddress = NULL;
       
   185             delete iMatchName;
       
   186             iMatchName = NULL;
       
   187 
       
   188             iMatchAddress = iContactAddressMatcher->GetAddressL();    
       
   189             iMatchName = iContactAddressMatcher->GetNameL(); 
       
   190             if (    iMatchAddress
       
   191                 &&  iMatchAddress->Length() )
       
   192                 {
       
   193                 // Use found address 
       
   194                 primaryAddress.Set( FoundContactAddressL() );
       
   195                 primaryAddressType = 
       
   196                     MsvUiServiceUtilitiesInternal::ResolveAddressTypeL( primaryAddress );
       
   197                 
       
   198                 // Use 'remote' alias, if it is visible on the UI
       
   199                 if ( iPrimaryName.Length() == 0 )
       
   200                     {
       
   201                     primaryName.Set( FoundContactNameL() );
       
   202                     }
       
   203                 }
       
   204             else 
       
   205                 {
       
   206                 // If found contact had not address, use primary address whatever it was. 
       
   207                 // Ignore also found name
       
   208                 primaryAddress.Set( iPrimaryAddress );
       
   209                 primaryName.Set( iPrimaryName );
       
   210                 }
       
   211                 
       
   212             }
       
   213         else if ( foundAddressType == EMuiuAddressTypePhoneNumber )
       
   214             {                        
       
   215             // Use search results
       
   216             primaryAddress.Set( FoundContactAddressL() );
       
   217             primaryAddressType = 
       
   218                 MsvUiServiceUtilitiesInternal::ResolveAddressTypeL( primaryAddress );
       
   219                             
       
   220             // Use 'remote' alias, if it is visible on the UI
       
   221             if ( iPrimaryName.Length() == 0 )
       
   222                 {
       
   223                 primaryName.Set( FoundContactNameL() );
       
   224                 }
       
   225             }
       
   226         else if ( primaryAddressType == EMuiuAddressTypePhoneNumber )
       
   227             {
       
   228             //  Use original address  
       
   229             primaryAddress.Set( iPrimaryAddress );
       
   230             primaryName.Set( iPrimaryName );              
       
   231             }
       
   232         else
       
   233             {
       
   234             primaryAddressType = EMuiuAddressTypeNone;
       
   235             }
       
   236         }
       
   237     else if ( preferredCallType != EMuiuCallTypeVoip )
       
   238         {
       
   239         return EFalse;
       
   240         }
       
   241     else // preferredCallType == EMuiuCallTypeVoip. Use original address information
       
   242         {
       
   243         primaryAddress.Set( iPrimaryAddress );
       
   244         primaryName.Set( iPrimaryName );
       
   245         }
       
   246 
       
   247     MsvUiServiceUtilitiesInternal::InternetOrVoiceCallServiceL( 
       
   248         iEikEnv,
       
   249         *iVoipExtension,
       
   250         primaryAddress,
       
   251         primaryName,
       
   252         primaryAddressType,
       
   253         iSecondaryAddress,
       
   254         secondaryAddressType,
       
   255         EFalse );
       
   256     return ret;
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------
       
   260 // CMuiuContactService::CallL
       
   261 // ---------------------------------------------------------
       
   262 EXPORT_C TBool CMuiuContactService::CallL( CItemFinder* aSecondaryItem )
       
   263     {
       
   264     TPtrC focusedAddr = KNullDesC( );
       
   265     if ( aSecondaryItem )
       
   266         {
       
   267         CItemFinder::CFindItemExt& item =
       
   268             aSecondaryItem->CurrentItemExt();
       
   269         if (    item.iItemDescriptor
       
   270             &&  (   item.iItemType == CItemFinder::EPhoneNumber
       
   271                 ||  item.iItemType == CItemFinder::EEmailAddress ) )
       
   272             {
       
   273             focusedAddr.Set( *(item.iItemDescriptor) );
       
   274             }
       
   275         }
       
   276     return CallL( focusedAddr );
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------
       
   280 // CMuiuContactService::IsContactFound
       
   281 // ---------------------------------------------------------
       
   282 EXPORT_C TBool CMuiuContactService::IsContactFound() const
       
   283     {
       
   284     if ( iMatchAddress )
       
   285         {
       
   286         return iMatchAddress->Length();
       
   287         }
       
   288     return EFalse;
       
   289     }
       
   290     
       
   291 // ---------------------------------------------------------
       
   292 // CMuiuContactService::FoundContactAddressL
       
   293 // ---------------------------------------------------------
       
   294 EXPORT_C TPtrC CMuiuContactService::FoundContactAddressL() const
       
   295     {
       
   296     if ( iMatchAddress )
       
   297         {
       
   298         return *iMatchAddress;
       
   299         }
       
   300     return KNullDesC();
       
   301     }
       
   302     
       
   303 // ---------------------------------------------------------
       
   304 // CMuiuContactService::FoundContactNameL
       
   305 // ---------------------------------------------------------
       
   306 EXPORT_C TPtrC CMuiuContactService::FoundContactNameL() const
       
   307     {
       
   308     if ( iMatchName )
       
   309         {
       
   310         return *iMatchName;
       
   311         }
       
   312     return KNullDesC();
       
   313     }
       
   314     
       
   315 // ---------------------------------------------------------
       
   316 // CMuiuContactService::IsVoipSupported
       
   317 // ---------------------------------------------------------
       
   318 EXPORT_C TBool CMuiuContactService::IsVoipSupported() const
       
   319     {        
       
   320     if (    iVoipExtension
       
   321         &&  iVoipExtension->IsVoIPSupported( ) )
       
   322         {
       
   323         return ETrue;
       
   324         }
       
   325     else
       
   326         {
       
   327         return EFalse;
       
   328         }
       
   329     }
       
   330     
       
   331 // ---------------------------------------------------------
       
   332 // CMuiuContactService::MatchDone
       
   333 // ---------------------------------------------------------
       
   334 TInt CMuiuContactService::MatchDone( TAny* aCallService )
       
   335     {
       
   336     CMuiuContactService* caller =
       
   337         static_cast<CMuiuContactService*>( aCallService );
       
   338     caller->iWait.AsyncStop( );
       
   339     return KErrNone;
       
   340     }
       
   341 
       
   342                                   
       
   343 // End of File
       
   344