phoneengine/PhoneCntFinder/ContactService/src/cphcntspeeddialimpl.cpp
branchRCL_3
changeset 62 5266b1f337bd
child 81 c26cc2a7c548
equal deleted inserted replaced
61:41a7f70b3818 62:5266b1f337bd
       
     1 /*
       
     2 * Copyright (c)  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 CPhCntSpeedDialImpl class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <spdiadialogs.h>
       
    20 #include <MVPbkContactLink.h>
       
    21 #include <PbkFields.hrh>
       
    22 #include <avkon.mbg>
       
    23 #include <eikimage.h> 
       
    24 #include <aknconsts.h>
       
    25 
       
    26 #include "CPhCntSpeedDialMonitor.h"
       
    27 #include "cphcntspeeddialimpl.h"
       
    28 #include "cphcntspeeddialcontactlinkfetch.h"
       
    29 #include "MPhoneCntPbkOwner.h"
       
    30 #include "cphcntfetchcontact.h"
       
    31 #include "CPhCntContactStores.h"
       
    32 #include "MPhCntContactManager.h"
       
    33 #include "CPhCntContact.h"
       
    34 #include "cphcntvpbkcontactid.h"
       
    35 #include "CPhCntContactManager.h"
       
    36 #include "pevirtualengine.h"
       
    37 
       
    38 // Characters that are needed to be stripped out 
       
    39 // from phone number before dialing.
       
    40 _LIT( KInvalidPhonenumberCharacters, " ()-" );
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // Default constructor.
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CPhCntSpeedDialImpl::CPhCntSpeedDialImpl( MPhoneCntPbkOwner& aPbkOwner ) : 
       
    49     iContactManager( *aPbkOwner.ContactManager() ),
       
    50     iPbkOwner( aPbkOwner )
       
    51     {
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CPhCntSpeedDialImpl::ConstructL
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 void CPhCntSpeedDialImpl::ConstructL()
       
    59     {
       
    60     iSpeedDialContactLinkFetcher = 
       
    61         CPhCntSpeedDialContactLinkFetch::NewL( iContactManager );
       
    62         
       
    63     iContactStores = CPhCntContactStores::NewL( iContactManager );
       
    64         
       
    65     iContactFetcher = CPhCntFetchContact::NewL( *iContactStores );
       
    66     }
       
    67     
       
    68 // ---------------------------------------------------------------------------
       
    69 //  CPhCntSpeedDialImpl::FetchContact
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 TInt CPhCntSpeedDialImpl::FetchContact( 
       
    73     TInt aSpeedDialPosition,
       
    74     CPhCntContact*& aContact )
       
    75     {
       
    76     TRAPD( err, 
       
    77         const MVPbkContactLink& linkToSpeedDialContact = 
       
    78             iSpeedDialContactLinkFetcher->FetchSpeedDialLinkL( 
       
    79                 aSpeedDialPosition );
       
    80                 
       
    81     
       
    82         err = 
       
    83             iContactFetcher->FetchContact( linkToSpeedDialContact, aContact );
       
    84     )
       
    85     return err;
       
    86     }
       
    87     
       
    88 // ---------------------------------------------------------------------------
       
    89 //  CPhCntSpeedDialImpl::CopyNumberL
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CPhCntSpeedDialImpl::CopyNumberL( 
       
    93     TDes& aCopyTo, 
       
    94     const TDesC& aNumber )
       
    95     {
       
    96     if( aCopyTo.MaxLength() >= aNumber.Length() ) 
       
    97         {
       
    98         aCopyTo.Copy( aNumber );
       
    99         }
       
   100     else
       
   101         {
       
   102         User::Leave( KErrArgument );
       
   103         }
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 //  CPhCntSpeedDialImpl::ParseNumber
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CPhCntSpeedDialImpl::ParseNumber( TDes& aNumber )
       
   111     {
       
   112     TBuf< KPEPhoneNumberMaxLength > parsedNumber = KNullDesC();
       
   113     TLex parser( aNumber );
       
   114     TChar c;
       
   115     while( !parser.Eos() )
       
   116         {
       
   117         c = parser.Get();
       
   118         if ( KErrNotFound == KInvalidPhonenumberCharacters().Locate( c ) )
       
   119             {
       
   120             parsedNumber.Append( c );
       
   121             }
       
   122         }
       
   123     aNumber = parsedNumber;
       
   124     }
       
   125 	
       
   126 // ---------------------------------------------------------------------------
       
   127 //  CPhCntSpeedDialImpl::CopyContactInfoToFieldInfoL
       
   128 // ---------------------------------------------------------------------------
       
   129 //  
       
   130 void CPhCntSpeedDialImpl::CopyContactInfoToFieldInfoL( 
       
   131         CPhCntContact& aContact,
       
   132         TInt aSpeedDialPosition, 
       
   133         TSpdDialFieldInfo& aFieldInfo )
       
   134     {
       
   135 	TPhCntNumber speedDial = aContact.SpeedDialNumber( aSpeedDialPosition );    
       
   136 	aFieldInfo.iNumberType = speedDial.Type();
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CPhCntSpeedDialImpl::NewL
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 CPhCntSpeedDialImpl* CPhCntSpeedDialImpl::NewL(
       
   144     MPhoneCntPbkOwner& aPbkOwner )
       
   145     {
       
   146     CPhCntSpeedDialImpl* self = 
       
   147         CPhCntSpeedDialImpl::NewLC( aPbkOwner );
       
   148         
       
   149     CleanupStack::Pop( self );
       
   150     return self;
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CPhCntSpeedDialImpl::NewLC
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 CPhCntSpeedDialImpl* CPhCntSpeedDialImpl::NewLC(
       
   158     MPhoneCntPbkOwner& aPbkOwner )
       
   159     {
       
   160     CPhCntSpeedDialImpl* self = new( ELeave ) 
       
   161         CPhCntSpeedDialImpl( aPbkOwner );
       
   162         
       
   163     CleanupStack::PushL( self );
       
   164     self->ConstructL();
       
   165     return self;
       
   166     }
       
   167 
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // Destructor
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 CPhCntSpeedDialImpl::~CPhCntSpeedDialImpl()
       
   174     {
       
   175     delete iContactFetcher;
       
   176     delete iContactStores;
       
   177     delete iSpeedDialContactLinkFetcher;
       
   178     delete iSpdDial;
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 //  CPhCntSpeedDialImpl::GetSpeedDialFieldInfoL
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void CPhCntSpeedDialImpl::GetSpeedDialFieldInfoL( 
       
   186     TInt aSpeedDialPosition,
       
   187     TSpdDialFieldInfo& aFieldInfo )
       
   188     {    
       
   189     CPhCntContact* contact = NULL;
       
   190     User::LeaveIfError( FetchContact( aSpeedDialPosition, contact ) );
       
   191     
       
   192     CleanupStack::PushL( contact );
       
   193    
       
   194     CopyContactInfoToFieldInfoL( *contact, aSpeedDialPosition, aFieldInfo );
       
   195         
       
   196     CleanupStack::PopAndDestroy( contact );
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CPhCntSpeedDialImpl::GetSpeedDialFieldL
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 TInt CPhCntSpeedDialImpl::GetSpeedDialFieldL( 
       
   204     TInt aSpeedDialPosition, 
       
   205     TDes& aPhoneNumber )
       
   206     {
       
   207     CPhCntContact* contact = NULL;
       
   208     const TInt err = FetchContact( aSpeedDialPosition, contact );
       
   209     if( !err )
       
   210         {
       
   211         CleanupStack::PushL( contact );
       
   212         TPhCntNumber speedDial( contact->SpeedDialNumber( aSpeedDialPosition ) );
       
   213         CopyNumberL( aPhoneNumber, speedDial.Number() );        
       
   214         CleanupStack::PopAndDestroy( contact );
       
   215         ParseNumber( aPhoneNumber );
       
   216         }
       
   217     return err;
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // CPhCntSpeedDialImpl::GetSpeedDialFieldL
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 TInt CPhCntSpeedDialImpl::GetSpeedDialFieldL(
       
   225     TInt aSpeedDialPosition, 
       
   226     TDes& aPhoneNumber,
       
   227     TSpdDialFieldInfo& aFieldInfo )
       
   228     {
       
   229     CPhCntContact* contact = NULL;
       
   230     const TInt err = FetchContact( aSpeedDialPosition, contact );
       
   231     
       
   232     if( !err )
       
   233         {
       
   234         CleanupStack::PushL( contact );
       
   235         TPhCntNumber speedDial( contact->SpeedDialNumber( aSpeedDialPosition ) );
       
   236         CopyNumberL( aPhoneNumber, speedDial.Number() );         
       
   237         CopyContactInfoToFieldInfoL( *contact, aSpeedDialPosition, aFieldInfo );        
       
   238         CleanupStack::PopAndDestroy( contact );
       
   239         ParseNumber( aPhoneNumber );
       
   240         }
       
   241     return err;
       
   242     }
       
   243     
       
   244 // -----------------------------------------------------------------------------
       
   245 // CPhCntSpeedDialImpl::FetchNumberL
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 TInt CPhCntSpeedDialImpl::FetchNumberL(
       
   249             TInt aSpeedDialPosition,
       
   250             TDes& aPhoneNumber )
       
   251     {
       
   252     CPhCntContact* contact = NULL;
       
   253     TInt err = FetchContact( aSpeedDialPosition, contact );
       
   254     
       
   255     if( !err )
       
   256         {
       
   257         CleanupStack::PushL( contact );
       
   258         TPhCntNumber speedDial( contact->SpeedDialNumber( aSpeedDialPosition ) );
       
   259         CopyNumberL( aPhoneNumber, speedDial.Number() );        
       
   260         CleanupStack::PopAndDestroy( contact );
       
   261         }
       
   262     return err;
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CPhCntSpeedDialImpl::AssignSpeedDialFieldL
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 TInt CPhCntSpeedDialImpl::AssignSpeedDialFieldL(
       
   270             TInt aSpeedDialPosition,
       
   271             TDes& aPhoneNumber )
       
   272     {
       
   273     CVPbkContactManager* contactMg = 
       
   274         &iPbkOwner.ContactManager()->ContactManager();
       
   275     if ( !iSpdDial )
       
   276         {
       
   277         iSpdDial = CSpdiaDialogs::NewL( *contactMg );    
       
   278         }    
       
   279     MVPbkContactLink *link = NULL;
       
   280     TInt err = iSpdDial->ShowAssign( aSpeedDialPosition, link );
       
   281     delete iSpdDial;
       
   282     iSpdDial = NULL;
       
   283     delete link;
       
   284     link = NULL;
       
   285     
       
   286     if ( err == KErrNone )
       
   287         {
       
   288         err = FetchNumberL( aSpeedDialPosition, aPhoneNumber );    
       
   289         }
       
   290     return err;
       
   291     }
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CPhCntSpeedDialImpl::AssignSpeedDialFieldL
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 TInt CPhCntSpeedDialImpl::AssignSpeedDialFieldL(
       
   298             TInt aSpeedDialPosition,
       
   299             TDes& aPhoneNumber,
       
   300             TSpdDialFieldInfo& aFieldInfo )
       
   301     {
       
   302     TInt err = AssignSpeedDialFieldL( aSpeedDialPosition, aPhoneNumber );
       
   303     if ( err == KErrNone )
       
   304         {
       
   305         GetSpeedDialFieldInfoL( aSpeedDialPosition, aFieldInfo );
       
   306         }
       
   307     return err;
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // CPhCntSpeedDialImpl::Cancel
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 void CPhCntSpeedDialImpl::Cancel()
       
   315     {
       
   316     if ( iSpdDial )
       
   317         {
       
   318         iSpdDial->Cancel();
       
   319         }
       
   320     }
       
   321     
       
   322 // -----------------------------------------------------------------------------
       
   323 // CPhCntSpeedDialImpl::CreateNumberTypeIconLC
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 CEikImage* CPhCntSpeedDialImpl::CreateNumberTypeIconLC( 
       
   327     TInt aNumberType )
       
   328     {
       
   329     TUint icon;
       
   330     TUint mask;
       
   331     switch ( aNumberType )
       
   332         {
       
   333         case EPbkFieldIdPhoneNumberMobile:
       
   334             icon = EMbmAvkonQgn_prop_nrtyp_mobile;
       
   335             mask = EMbmAvkonQgn_prop_nrtyp_mobile_mask;
       
   336             break;
       
   337         case EPbkFieldIdPagerNumber:
       
   338             icon = EMbmAvkonQgn_prop_nrtyp_pager;
       
   339             mask = EMbmAvkonQgn_prop_nrtyp_pager_mask;
       
   340             break;
       
   341         case EPbkFieldIdPhoneNumberVideo:
       
   342             icon = EMbmAvkonQgn_prop_nrtyp_video;
       
   343             mask = EMbmAvkonQgn_prop_nrtyp_video_mask;
       
   344             break;
       
   345         case EPbkFieldIdVOIP:
       
   346             icon = EMbmAvkonQgn_prop_nrtyp_voip;
       
   347             mask = EMbmAvkonQgn_prop_nrtyp_voip_mask;
       
   348             break;
       
   349         case EPbkFieldIdPhoneNumberGeneral:
       
   350         case EPbkFieldIdPhoneNumberHome:
       
   351         case EPbkFieldIdPhoneNumberWork:
       
   352         case EPbkFieldIdFaxNumber:
       
   353         default:
       
   354             icon = EMbmAvkonQgn_prop_nrtyp_phone;
       
   355             mask = EMbmAvkonQgn_prop_nrtyp_phone_mask;
       
   356             break;
       
   357         }
       
   358 
       
   359     CEikImage* iconImg = new ( ELeave ) CEikImage;
       
   360     CleanupStack::PushL( iconImg );
       
   361 
       
   362     CFbsBitmap* iconBmp = new ( ELeave ) CFbsBitmap;
       
   363     CleanupStack::PushL( iconBmp );
       
   364     User::LeaveIfError( iconBmp->Load( 
       
   365         KAvkonBitmapFile(),
       
   366         icon,
       
   367         ETrue ) );
       
   368 
       
   369     CFbsBitmap* iconMaskBmp = new ( ELeave ) CFbsBitmap;
       
   370     CleanupStack::PushL( iconMaskBmp );
       
   371     User::LeaveIfError( iconMaskBmp->Load( 
       
   372         KAvkonBitmapFile(), 
       
   373         mask,
       
   374         ETrue ) );
       
   375     
       
   376     CleanupStack::Pop( iconMaskBmp );
       
   377     CleanupStack::Pop( iconBmp );
       
   378 
       
   379     iconImg->SetPicture( iconBmp, iconMaskBmp );
       
   380     iconImg->SetPictureOwnedExternally( EFalse );
       
   381 
       
   382     return iconImg;
       
   383     }
       
   384         
       
   385 //  End of File