phonebookui/Speeddial/VPbkControlSrc/speeddialprivate.cpp
branchRCL_3
changeset 20 f4a778e096c2
child 21 9da50d567e3c
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2002 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:     A utility that provides services to both the Speeddial and
       
    15 *                PhoneBook applications for getting and setting speeddial
       
    16 *                number configuration.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 // INCLUDE FILES
       
    27 #include <akninputblock.h>
       
    28 #include <bldvariant.hrh>
       
    29 #include <gulicon.h>
       
    30 #include <akncontext.h>
       
    31 #include <akntitle.h>
       
    32 #include <AknQueryDialog.h>
       
    33 #include <aknlists.h>
       
    34 #include <bautils.h>
       
    35 #include <aknnotedialog.h>
       
    36 #include <aknnotecontrol.h>
       
    37 #include <aknnotewrappers.h>
       
    38 #include <sysutil.h>
       
    39 #include <ErrorUI.h>
       
    40 #include <vmnumber.h>
       
    41 #include <centralrepository.h>
       
    42 #include <settingsinternalcrkeys.h>
       
    43 #include <SpeeddialPrivateCRKeys.h>
       
    44 
       
    45 
       
    46 #include <StringLoader.h>
       
    47 #include <SpdCtrl.rsg>
       
    48 #include <spdctrl.mbg>
       
    49 #include <avkon.mbg>
       
    50 #include <gdi.h>
       
    51 #include <AknIconArray.h>
       
    52 
       
    53 #include <aknlayoutscalable_apps.cdl.h>
       
    54 #include <layoutmetadata.cdl.h>
       
    55 #include <AknsBasicBackgroundControlContext.h>
       
    56 #include <AknsDrawUtils.h>
       
    57 #include <AknsUtils.h>
       
    58 #include <AknIconUtils.h>
       
    59 #include <applayout.cdl.h>
       
    60 #include <data_caging_path_literals.hrh>
       
    61 #include <f32file.h>
       
    62 #include <featmgr.h>
       
    63 #include "SpdiaGridVPbk.h"
       
    64 #include "SpdiaGridDlgVPbk.h"
       
    65 #include "SpdiaIndexDataVPbk.h"
       
    66 #include "SpdiaControl.hrh"
       
    67 #include "Speeddial.laf"
       
    68 #include "SpdiaPanic.h"
       
    69 
       
    70 #include "speeddialprivate.h"
       
    71 #include <CVPbkFieldTypeRefsList.h>
       
    72 #include <MPbk2FieldPropertyArray.h>
       
    73 #include <TPbk2IconId.h>
       
    74 #include <MVPbkContactOperationBase.h>
       
    75 #include <Pbk2FieldPropertiesFactory.h>
       
    76 #include <MPbk2FieldProperty.h>
       
    77 #include <CVPbkSpeedDialAttribute.h>
       
    78 #include <MVPbkContactFieldTextData.h>
       
    79 #include <MVPbkContactFieldUriData.h>
       
    80 #include <CVPbkContactFieldIterator.h>
       
    81 #include <CPbk2IconFactory.h>
       
    82 #include <CPbk2SortOrderManager.h>
       
    83 #include <MPbk2ContactNameFormatter.h>
       
    84 #include <Pbk2ContactNameFormatterFactory.h>
       
    85 #include <CVPbkFieldTypeSelector.h>
       
    86 #include <VPbkContactViewFilterBuilder.h>
       
    87 #include <CVPbkContactStoreUriArray.h>
       
    88 #include <TVPbkContactStoreUriPtr.h>
       
    89 #include <CVPbkContactLinkArray.h>
       
    90 #include <MVPbkContactStoreList.h>
       
    91 #include <MVPbkContactStore.h>
       
    92 #include <MVPbkContactLink.h>
       
    93 #include <CVPbkContactLinkArray.h>
       
    94 #include <MVPbkContactStoreProperties.h>
       
    95 #include <voicemailboxdomaincrkeys.h>
       
    96 #include <AiwGenericParam.h>
       
    97 #include <AiwServiceHandler.h>
       
    98 #include <telvmbxsettingscrkeys.h>
       
    99 
       
   100 #include <VPbkEng.rsg>
       
   101 #include <AiwContactAssignDataTypes.h>
       
   102 
       
   103 #include "SpdiaContainer.h"
       
   104 #include <MPbk2FieldPropertyArray2.h>
       
   105 #include <MPbk2FieldProperty2.h>
       
   106 #include <MPbk2FieldProperty.h>
       
   107 
       
   108 // LOCAL CONSTANTS AND MACROS
       
   109 //This order is based on 'Standard field ids' (PbkFields.hrh)
       
   110 
       
   111 const TUint KFieldIds[] = 
       
   112 {
       
   113     R_VPBK_FIELD_TYPE_LANDPHONEHOME,
       
   114     R_VPBK_FIELD_TYPE_MOBILEPHONEHOME,
       
   115     R_VPBK_FIELD_TYPE_VIDEONUMBERHOME,
       
   116     R_VPBK_FIELD_TYPE_FAXNUMBERHOME,
       
   117     R_VPBK_FIELD_TYPE_VOIPHOME,
       
   118     R_VPBK_FIELD_TYPE_LANDPHONEWORK,
       
   119     R_VPBK_FIELD_TYPE_MOBILEPHONEWORK,
       
   120     R_VPBK_FIELD_TYPE_VIDEONUMBERWORK,
       
   121     R_VPBK_FIELD_TYPE_FAXNUMBERWORK,
       
   122     R_VPBK_FIELD_TYPE_VOIPWORK,
       
   123     R_VPBK_FIELD_TYPE_LANDPHONEGEN,
       
   124     R_VPBK_FIELD_TYPE_MOBILEPHONEGEN,
       
   125     R_VPBK_FIELD_TYPE_VIDEONUMBERGEN,
       
   126     R_VPBK_FIELD_TYPE_FAXNUMBERGEN,
       
   127     R_VPBK_FIELD_TYPE_VOIPGEN,
       
   128     R_VPBK_FIELD_TYPE_POC,
       
   129     R_VPBK_FIELD_TYPE_SWIS,
       
   130     R_VPBK_FIELD_TYPE_SIP,
       
   131     R_VPBK_FIELD_TYPE_PAGERNUMBER,
       
   132     R_VPBK_FIELD_TYPE_ASSTPHONE,
       
   133     R_VPBK_FIELD_TYPE_CARPHONE,
       
   134     R_VPBK_FIELD_TYPE_IMPP
       
   135 };
       
   136 
       
   137 
       
   138 
       
   139 const TInt KCellRowCount(3);
       
   140 const TInt KCellColCount(3);
       
   141 const TInt KMaxIndex(8);
       
   142 const TInt KVoiceMail(0);
       
   143 
       
   144 
       
   145 const TInt KLayoutCount(5);
       
   146 const TInt KNullIndexData(-1);
       
   147 const TInt32 KVmbxUid(0x100058F5) ;
       
   148 const TInt KOperatorNameLength(100);
       
   149 const TInt KContactFormattingFlags = MPbk2ContactNameFormatter::EPreserveLeadingSpaces | MPbk2ContactNameFormatter::EReplaceNonGraphicChars;
       
   150 
       
   151 _LIT(KNullCell, "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t%d\t");
       
   152 _LIT(KDesTab, "\t");
       
   153 _LIT(KDesTab2, "\t\t");
       
   154 
       
   155 
       
   156 class TXspIconHelper
       
   157     {
       
   158 
       
   159     public:    
       
   160     	TXspIconHelper( TInt aIndex, const TDesC& aLable);
       
   161     	TInt IconIndex() const;
       
   162     	TDesC& LableText();
       
   163     private:
       
   164     	TInt iIndex;
       
   165     	TBuf<50> iLableText;
       
   166     	      
       
   167     };
       
   168 
       
   169 TXspIconHelper::TXspIconHelper(TInt aIndex, const TDesC& aLable):
       
   170     iIndex (aIndex),
       
   171     iLableText (aLable)
       
   172 	{
       
   173 	}
       
   174 
       
   175 inline TInt TXspIconHelper::IconIndex() const 
       
   176 	{
       
   177 	return iIndex;
       
   178 	}
       
   179 
       
   180 inline TDesC& TXspIconHelper::LableText() 
       
   181 	{
       
   182 	return iLableText;
       
   183 	}
       
   184 
       
   185 // ---------------------------------------------------------
       
   186 // CSpeedDialPrivate::NewL()
       
   187 // ---------------------------------------------------------
       
   188 //
       
   189 	
       
   190 
       
   191 	EXPORT_C CSpeedDialPrivate*	CSpeedDialPrivate::NewL(CVPbkContactManager* aContactManager )
       
   192 	{
       
   193 		CSpeedDialPrivate* self = new(ELeave) CSpeedDialPrivate(aContactManager);
       
   194 		CleanupStack::PushL(self);
       
   195     	self->ConstructL();
       
   196     	CleanupStack::Pop();  // self
       
   197     	return self;
       
   198 	}
       
   199 
       
   200 // ---------------------------------------------------------
       
   201 // CSpdiaControl::CSpdiaControl
       
   202 //
       
   203 // ---------------------------------------------------------
       
   204 //
       
   205 
       
   206 	CSpeedDialPrivate::CSpeedDialPrivate(CVPbkContactManager* aContactManager):
       
   207                         iShadowLayout(NULL),
       
   208                         iBgContext(NULL),
       
   209                         iCurrentIndex( -1 ),
       
   210                         iDialSkinBmp(NULL),
       
   211                         iSkinIcons(NULL),
       
   212                         iContactManager(aContactManager),
       
   213                         iImageManager(NULL),
       
   214                         iContactLink(NULL),
       
   215                         iContact(NULL),
       
   216                         iContactLinkArray(NULL),
       
   217                         iSpeedDial(NULL),
       
   218                         iUpdateFlag(EFalse),
       
   219                         iSdmArray(NULL),
       
   220                         iWait(NULL),
       
   221                         iVideoMail(0),
       
   222                         iMail(NULL),
       
   223                         iFetchmail(EFalse),
       
   224                         iServiceHandler(NULL),						
       
   225                         iCancelFlag(0),
       
   226                         iRemoveConfirmQueryDialog( NULL )
       
   227                         /*iOperationComplete(EFalse),*/
       
   228 	{
       
   229 
       
   230 	}
       
   231 
       
   232 // ---------------------------------------------------------
       
   233 // CSpeedDialPrivate::ConstructL
       
   234 //
       
   235 // ---------------------------------------------------------
       
   236 //
       
   237 	void CSpeedDialPrivate::ConstructL()
       
   238 	{
       
   239 		 TInt tmp = 1;
       
   240 
       
   241 	   	_LIT(KMbmFileName, "Z:spdctrl.mbm");
       
   242 		_LIT(KRscFileName, "Z:spdctrl.rsc" );
       
   243 
       
   244 		TParse* fpMbm = new(ELeave) TParse ();
       
   245 		fpMbm->Set (KMbmFileName, &KDC_APP_BITMAP_DIR, NULL);
       
   246 		iBmpPath.Copy(fpMbm ->FullName());
       
   247 		delete fpMbm;
       
   248 		fpMbm=NULL;
       
   249 
       
   250 		TParse* fpRsc = new(ELeave) TParse ();
       
   251 		fpRsc->Set (KRscFileName, &KDC_RESOURCE_FILES_DIR, NULL);
       
   252 		
       
   253 		TBuf<254> rscPath;
       
   254 		rscPath.Copy(fpRsc ->FullName());
       
   255 		
       
   256 		delete fpRsc;
       
   257 		fpRsc=NULL;
       
   258 
       
   259 		CRepository* repository = CRepository::NewLC(KCRUidSpeedDialLV);
       
   260 		repository->Get( KSpeedDialLVFlags, tmp );
       
   261 
       
   262 		iBooleanVarForAddingDialogVariation  = ( tmp == 1);
       
   263 		
       
   264 		CleanupStack::PopAndDestroy(); // pop-destroy repository
       
   265 
       
   266 
       
   267 	    TFileName fileName(rscPath);
       
   268 	    BaflUtils::NearestLanguageFile(iCoeEnv->FsSession(), fileName);
       
   269 	    iFileOffset = iCoeEnv->AddResourceFileL(fileName);
       
   270 
       
   271 	    iSdmCount = KCellRowCount * KCellColCount;
       
   272 	    iGridUsed = EGridNoUse;
       
   273 
       
   274 	    iIconArray = new (ELeave)CAknIconArray(iSdmCount);
       
   275 	    iSdmArray = new (ELeave) CArrayFixFlat<TSpdiaIndexDataVPbk>(iSdmCount);
       
   276 	    TSpdiaIndexDataVPbk spDialData;
       
   277 	    iSdmArray->AppendL(spDialData, iSdmCount);
       
   278 
       
   279 		iDialSkinBmp = new (ELeave)RArray<TAknsItemID>(KArraySize);
       
   280 		iSkinIcons = new (ELeave)RArray<TAknsItemID>(KArraySize);
       
   281 	    iShadowLayout = new (ELeave) CArrayFixFlat<TAknLayoutRect> (KLayoutCount);
       
   282 	    for (TInt i(0); i < KLayoutCount; ++i)
       
   283 	        {
       
   284 	        TAknLayoutRect rect;
       
   285 	        iShadowLayout->AppendL(rect);
       
   286 	        }
       
   287 
       
   288 			
       
   289 		iSpeedDial = CVPbkSpeedDialAttribute::NewL();
       
   290 		
       
   291 		iAttributeManager = &(iContactManager->ContactAttributeManagerL());
       
   292 
       
   293 		iThumbNailFieldType = iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_THUMBNAILPIC ); 
       
   294 		iImageManager =  CPbk2ImageManager::NewL(*iContactManager);
       
   295 		iContactLinkArray = NULL;
       
   296 	    iServiceHandler = CAiwServiceHandler::NewL();
       
   297 		iServiceHandler->AttachL( R_SPEEDDIAL_EMAIL_SELECTION_INTEREST );
       
   298 		iServiceHandler->AttachL( R_SPDIA_SINGLE_ASSIGN_INTEREST );
       
   299 		iWait = new( ELeave )CActiveSchedulerWait();
       
   300         iWaitFetchmail = new( ELeave )CActiveSchedulerWait();
       
   301 		
       
   302 		
       
   303 		iError = KErrNone;
       
   304 
       
   305         MVPbkContactStoreList& storeList = iContactManager->ContactStoresL();
       
   306         for(TInt count=0;count<storeList.Count();++count)
       
   307         {
       
   308         	iOperationComplete = EFalse;
       
   309         	storeList.At(count).OpenL(*this);
       
   310         	while(!iOperationComplete)
       
   311 	        {	
       
   312 	   			Wait();
       
   313 	        }
       
   314         }
       
   315    
       
   316         
       
   317 	    InitIndexDataL();
       
   318 	    
       
   319 	    iState = STATE_IDLE;
       
   320 	    
       
   321 		InitializeArray();
       
   322 
       
   323 	    // create skin context
       
   324 	    // Size is set in SizeChanged()
       
   325 	    iBgContext = CAknsBasicBackgroundControlContext::NewL(
       
   326 	        KAknsIIDQsnBgAreaMainQdial,
       
   327 	        TRect(0,0,0,0),
       
   328 	        EFalse );
       
   329 	        iPopupDialog = EFalse;
       
   330 
       
   331  	ivmbxvariation = CRepository::NewL( KCRUidVideoMailbox );
       
   332 	ivmbxvariation->Get( KVideoMbxSupport, iVmbxsupported );
       
   333 	
       
   334 	
       
   335 	CRepository*  vmbxkey2 = CRepository::NewL( KCRUidTelVideoMailbox );
       
   336     vmbxkey2->Get( KTelVideoMbxKey, iVmbxkeypos );
       
   337 	delete vmbxkey2;
       
   338 	vmbxkey2 = 	NULL      ;
       
   339 	// Initialize the bmp arrays
       
   340 	InitBmpArray();
       
   341 //#ifndef VIDEOMAILBOX_HIDDEN//its shown
       
   342 if(iVmbxsupported)
       
   343 	{
       
   344 	    iType = EVmbx;
       
   345 	}
       
   346 	
       
   347 else
       
   348         iType = EVmbx;
       
   349 	 iShowAssignCalled = EFalse;
       
   350 		
       
   351 	}
       
   352 
       
   353 
       
   354 // ---------------------------------------------------------
       
   355 // CSpeedDialPrivate::InitBmpArray
       
   356 //
       
   357 // ---------------------------------------------------------
       
   358 //
       
   359 void CSpeedDialPrivate::InitBmpArray()
       
   360 {
       
   361 		TInt i(0);
       
   362 		
       
   363 		// Possible values for iVmbxkeypos are 1 & 2
       
   364 		(iVmbxkeypos > 1) ? iVideoMail = 1 : iVideoMail = 0;
       
   365 		
       
   366 		 // Initialize grid bitmaps
       
   367 		 for (i = 0; i < 9; i++ )
       
   368 		 {
       
   369 		 	// EMbmSpdctrlQgn_graf_quick_one
       
   370 		 	if (0 == i)
       
   371 		 	{
       
   372 		 		
       
   373 		 		#ifdef __SCALABLE_ICONS
       
   374 				    iDialBmp[0] 	= EMbmSpdctrlQgn_menu_smsvo;
       
   375 				    iDialBmpMask[0]	= EMbmSpdctrlQgn_menu_smsvo_mask;
       
   376 				    
       
   377 				    iDialHindiBmp[0] 		= EMbmSpdctrlQgn_menu_smsvo;
       
   378 				    iDialHindiBmpMask[0]	= EMbmSpdctrlQgn_menu_smsvo_mask;
       
   379 				#else
       
   380 				    iDialBmp[0] = EMbmSpdctrlQgn_menu_smsvo_lst;
       
   381 				    iDialBmp[0] = EMbmSpdctrlQgn_menu_smsvo_lst_mask;
       
   382 				    
       
   383 				    iDialHindiBmp[0] 		= EMbmSpdctrlQgn_menu_smsvo_lst;
       
   384 				    iDialHindiBmpMask[0]	= EMbmSpdctrlQgn_menu_smsvo_lst_mask;
       
   385 				#endif
       
   386 				
       
   387 				continue;
       
   388 		 	}
       
   389 			
       
   390 			// EMbmSpdctrlQgn_graf_quick_two
       
   391 			if (1 == i)
       
   392 			{
       
   393 				// If Video Mailbox is via key2, then update with corresponding icons 
       
   394 				// in the 2nd location of the grid.
       
   395 				if ((0 < iVideoMail) &&(iVmbxsupported))
       
   396 				{
       
   397 					iDialBmp[1] 	= EMbmSpdctrlQgn_prop_video_mb;
       
   398 					iDialBmpMask[1] = EMbmSpdctrlQgn_prop_video_mb_mask;
       
   399 					
       
   400 					iDialHindiBmp[1] 		= EMbmSpdctrlQgn_prop_video_mb;
       
   401 					iDialHindiBmpMask[1] 	= EMbmSpdctrlQgn_prop_video_mb_mask;
       
   402 				}
       
   403 				// (else) VideoMailbox is via key 0
       
   404 				else
       
   405 				{
       
   406 					iDialBmp[1] 	= EMbmSpdctrlQgn_graf_quick_two;
       
   407 					iDialBmpMask[1] = EMbmSpdctrlQgn_graf_quick_two_mask;
       
   408 					
       
   409 					iDialHindiBmp[1] 		= EMbmSpdctrlQgn_graf_deva_quick_two;
       
   410 					iDialHindiBmpMask[1] 	= EMbmSpdctrlQgn_graf_deva_quick_two_mask;
       
   411 				}
       
   412 				
       
   413 				continue;
       
   414 			}
       
   415 			
       
   416 			iDialBmp[i]		= EMbmSpdctrlQgn_menu_smsvo + (2 * i);
       
   417 			iDialBmpMask[i]	= EMbmSpdctrlQgn_menu_smsvo + (2 * i) + 1;
       
   418 			
       
   419 			iDialHindiBmp[i]	= EMbmSpdctrlQgn_graf_deva_quick_one + (2 * i);
       
   420 			iDialHindiBmpMask[i]= EMbmSpdctrlQgn_graf_deva_quick_one + (2 * i) + 1;
       
   421 		 }
       
   422 
       
   423 }
       
   424 
       
   425 // ---------------------------------------------------------
       
   426 // CSpeedDialPrivate::~CSpeedDialPrivate
       
   427 //
       
   428 // ---------------------------------------------------------
       
   429 //
       
   430 	EXPORT_C CSpeedDialPrivate::~CSpeedDialPrivate()
       
   431     {
       
   432 
       
   433 	    //delete iThumbFactory;
       
   434 	    delete iShadowLayout;
       
   435 	    
       
   436 	    if (iGridUsed == EGridNoUse)
       
   437 	        {
       
   438 	        if (iIconArray)
       
   439 	            {
       
   440 	            iIconArray->ResetAndDestroy();
       
   441 	            delete iIconArray;
       
   442 	            }
       
   443 	        }
       
   444 	        
       
   445 	    ResetArray();
       
   446 	    delete iSdmArray;
       
   447 	    
       
   448 
       
   449 	    if (iCoeEnv != NULL)
       
   450 	        {
       
   451 	        iCoeEnv->DeleteResourceFile(iFileOffset);
       
   452 	        }
       
   453 	    delete iBgContext;
       
   454 	    
       
   455 		if(iDialSkinBmp != NULL)
       
   456 			{
       
   457 			iDialSkinBmp->Close();
       
   458 			delete iDialSkinBmp;
       
   459 			}
       
   460 		
       
   461 
       
   462 		if(iSkinIcons !=  NULL)
       
   463 			{
       
   464 			iSkinIcons->Close();
       
   465 			delete iSkinIcons;
       
   466 			}
       
   467 		
       
   468 		TRAP_IGNORE(
       
   469 				{
       
   470 					MVPbkContactStoreList& storeList =  iContactManager->ContactStoresL();
       
   471            		
       
   472            			for(TInt count=0;count<storeList.Count();++count)
       
   473         			{
       
   474         				storeList.At(count).Close(*this);
       
   475         			}
       
   476 				}
       
   477 			);		
       
   478 		
       
   479 		delete iImageManager;
       
   480 		delete iWait;
       
   481         delete iWaitFetchmail;
       
   482 		delete iContact;
       
   483 		delete iContactLinkArray;
       
   484 		delete iSpeedDial;
       
   485 		delete iQueryDialog;
       
   486 		delete ivmbxvariation;
       
   487 		if ( iServiceHandler )
       
   488 			{
       
   489 			delete iServiceHandler;
       
   490 			iServiceHandler = NULL;
       
   491 			}
       
   492     if ( iRemoveConfirmQueryDialog )
       
   493         {
       
   494         delete iRemoveConfirmQueryDialog;
       
   495         iRemoveConfirmQueryDialog = NULL;
       
   496         }
       
   497 		
       
   498     ixspIconInfoArray.Close();    
       
   499     }
       
   500        
       
   501 // ---------------------------------------------------------
       
   502 // CSpeedDialPrivate::InitializeArray
       
   503 //
       
   504 // ---------------------------------------------------------
       
   505 //   
       
   506 void CSpeedDialPrivate::InitializeArray()
       
   507     {
       
   508     iDialSkinBmp->Append(KAknsIIDQgnMenuSmsvoLst);
       
   509     iDialSkinBmp->Append(KAknsIIDQgnGrafQuickTwo);
       
   510     iDialSkinBmp->Append(KAknsIIDQgnGrafQuickThree);
       
   511     iDialSkinBmp->Append(KAknsIIDQgnGrafQuickFour);
       
   512     iDialSkinBmp->Append(KAknsIIDQgnGrafQuickFive);
       
   513     iDialSkinBmp->Append(KAknsIIDQgnGrafQuickSix);
       
   514     iDialSkinBmp->Append(KAknsIIDQgnGrafQuickSeven);
       
   515     iDialSkinBmp->Append(KAknsIIDQgnGrafQuickEight);
       
   516     iDialSkinBmp->Append(KAknsIIDQgnGrafQuickNine);
       
   517 
       
   518     iSkinIcons->Append(KAknsIIDQgnPropNrtypPhone);
       
   519     iSkinIcons->Append(KAknsIIDQgnPropNrtypHome);
       
   520     iSkinIcons->Append(KAknsIIDQgnPropNrtypWork);
       
   521     iSkinIcons->Append(KAknsIIDQgnPropNrtypMobile);
       
   522     iSkinIcons->Append(KAknsIIDQgnPropNrtypVideo);
       
   523     iSkinIcons->Append(KAknsIIDQgnPropNrtypFax);
       
   524     iSkinIcons->Append(KAknsIIDQgnPropNrtypPager);
       
   525     if ( FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) )
       
   526         {
       
   527         iSkinIcons->Append( KAknsIIDQgnPropNrtypVoip );  
       
   528 	}
       
   529     iSkinIcons->Append(KAknsIIDQgnPropNrtypEmail);
       
   530     iSkinIcons->Append(KAknsIIDQgnPropNrtypAddress);
       
   531     }
       
   532 
       
   533 // ---------------------------------------------------------
       
   534 // CSpeedDialPrivate::ResetArray
       
   535 //
       
   536 // ---------------------------------------------------------
       
   537 //   
       
   538 	void CSpeedDialPrivate::ResetArray()
       
   539     {
       
   540     	TInt index(0);
       
   541 	    if(iSdmArray!= NULL)
       
   542 	    {
       
   543 	 	    
       
   544 	    
       
   545 	    for (index = 0; index < iSdmArray->Count(); index++)
       
   546 	        {
       
   547 	        (*iSdmArray)[index].Reset();
       
   548 	        (*iSdmArray)[index].SetIndex(index);
       
   549 	        }
       
   550 	    }
       
   551     }
       
   552  
       
   553 // ---------------------------------------------------------
       
   554 // CSpeedDialPrivate::CreateFieldIconsL
       
   555 //
       
   556 // ---------------------------------------------------------
       
   557 //      
       
   558 	void CSpeedDialPrivate::CreateFieldIconsL(CArrayPtrFlat<CGulIcon>* aArray)
       
   559 	{
       
   560 		TInt arraySize = sizeof KFieldIds / sizeof KFieldIds[0];
       
   561 		TInt count =0;
       
   562 		const MVPbkFieldType* fieldType = NULL;
       
   563 		CGulIcon* icon = NULL;
       
   564 		
       
   565 		CVPbkFieldTypeRefsList* fieldTypeList = CVPbkFieldTypeRefsList::NewL();
       
   566 		CPbk2IconFactory* pbk2IconFactory = CPbk2IconFactory::NewL();
       
   567 
       
   568 	
       
   569 		for(count =0; count < arraySize;  ++count)
       
   570 		{
       
   571 			fieldType = iContactManager->FieldTypes().Find( KFieldIds[count] );
       
   572 			fieldTypeList->AppendL(*fieldType);	
       
   573 		}
       
   574 		
       
   575 		MPbk2FieldPropertyArray* aPropertyArray = Pbk2FieldPropertiesFactory::CreateLC(*fieldTypeList,&iContactManager->FsSession() );
       
   576 		
       
   577 		ixspIconInfoArray.Reset();
       
   578 		const TInt arrayCount = aPropertyArray->Count();
       
   579 		for(count =0; count < arrayCount; ++ count)
       
   580 		{
       
   581 		   icon = pbk2IconFactory->CreateIconL(aPropertyArray->At(count).IconId());
       
   582 		   aArray->AppendL(icon);
       
   583 		   
       
   584 		   // Append xSP icon info to helper array
       
   585 		   if ( aPropertyArray->At(count).FieldType().FieldTypeResId() == R_VPBK_FIELD_TYPE_IMPP )
       
   586 			   {
       
   587 			   const MPbk2FieldProperty& property = aPropertyArray->At(count);
       
   588 			   MPbk2FieldProperty2* property2 = reinterpret_cast<MPbk2FieldProperty2*>
       
   589 			           ( const_cast<MPbk2FieldProperty&> ( property ).FieldPropertyExtension(
       
   590 			                KMPbk2FieldPropertyExtension2Uid ) );
       
   591 			           			   
       
   592 			   TXspIconHelper helper( aArray->Count()-1, property2->XSpName() );		   
       
   593 			   ixspIconInfoArray.AppendL( helper );
       
   594 			   }
       
   595 		}		
       
   596 		CleanupStack::PopAndDestroy(aPropertyArray);
       
   597 		
       
   598 		delete fieldTypeList;
       
   599 		delete pbk2IconFactory;
       
   600 		
       
   601 	}
       
   602 // ---------------------------------------------------------
       
   603 // CSpeedDialPrivate::VoiceMailL  
       
   604 //
       
   605 // ---------------------------------------------------------
       
   606 //
       
   607 EXPORT_C TBool CSpeedDialPrivate::VoiceMailL(TDes& aNumber)
       
   608     {
       
   609     TBool result(ETrue);
       
   610 
       
   611     RVmbxNumber vmbx;
       
   612     CleanupClosePushL(vmbx); // So that Close() is called if a leave happens.
       
   613     if (vmbx.Open() == KErrNone)
       
   614         {
       
   615         TInt err2 = vmbx.GetVideoMbxNumber( aNumber );
       
   616 
       
   617         
       
   618 	if( iVmbxsupported )
       
   619 		{
       
   620 	        TInt err1 = vmbx.GetVmbxNumber( aNumber );
       
   621 	        TInt err2 = vmbx.GetVideoMbxNumber( aNumber );
       
   622 	                    
       
   623 	    if ( ( err1 == KErrNotFound || err1 == KErrNotSupported ) &&
       
   624 	         ( err2 == KErrNotFound || err2 == KErrNotSupported ))
       
   625 	        {
       
   626 	        iType = vmbx.SelectTypeL( EVmbxDefine );
       
   627 	        }
       
   628 	    else 
       
   629 	        {
       
   630 	        iType = vmbx.SelectTypeL( EVmbxCall );
       
   631 	        }   
       
   632 	        
       
   633 	        if( iType == EVmbxIP && !vmbx.IsVoIPProfilesFound() )
       
   634 	            {
       
   635 				TInt err(vmbx.GetVmbxAddressL(aNumber));
       
   636 		        if (err != KErrNone)
       
   637 		            {
       
   638 		            aNumber.Zero();
       
   639 		            if (err != KErrNotFound ||
       
   640 		                    !vmbx.QueryAddressL(EVmbxNotDefinedQuery, aNumber))
       
   641 		                {
       
   642 		                result = EFalse;
       
   643 		                }
       
   644 		            }
       
   645 	        	}
       
   646 	        else if( iType == EVmbxVideo )
       
   647 	            {
       
   648 				TInt err(vmbx.GetVideoMbxNumber(aNumber));
       
   649 				if (err != KErrNone)
       
   650 					{
       
   651 					aNumber.Zero();
       
   652 					if (err != KErrNotFound ||!vmbx.QueryVideoMbxNumberL(EVmbxNotDefinedQuery, aNumber))
       
   653 						{
       
   654 						result = EFalse;
       
   655 						}
       
   656 					}            
       
   657 	            }
       
   658 		    else if(iType ==EVmbx)
       
   659 		    	{
       
   660 				TInt err(vmbx.GetVmbxNumber(aNumber));
       
   661 				if (err != KErrNone)
       
   662 					{
       
   663 					aNumber.Zero();
       
   664 					if (err != KErrNotFound ||
       
   665 	                    !vmbx.QueryNumberL(EVmbxNotDefinedQuery, aNumber))
       
   666 						{
       
   667 						result = EFalse;
       
   668 						}
       
   669 					}
       
   670 	            }
       
   671 	           else
       
   672 	           {
       
   673 	           	result = EFalse;
       
   674 	           }
       
   675 		}
       
   676 	else
       
   677 		{
       
   678 		ExVoiceMailL(aNumber);
       
   679 		
       
   680 		}
       
   681        
       
   682         }
       
   683     CleanupStack::PopAndDestroy();  // It will call vmbx.Close()
       
   684     return result;
       
   685     }
       
   686     
       
   687 // ---------------------------------------------------------
       
   688 // CSpeedDialPrivate::ExVoiceMailL  
       
   689 //
       
   690 // ---------------------------------------------------------
       
   691 //
       
   692 EXPORT_C TBool CSpeedDialPrivate::ExVoiceMailL(TDes& aNumber)
       
   693     {
       
   694     TBool result(ETrue);
       
   695         RVmbxNumber vmbx;
       
   696     CleanupClosePushL(vmbx); // So that Close() is called if a leave happens.
       
   697   
       
   698   if (vmbx.Open() == KErrNone)
       
   699         {
       
   700 
       
   701 
       
   702     if( !vmbx.IsVoIPProfilesFound() && vmbx.SelectTypeL( EVmbxCall ) )
       
   703         	{
       
   704 			iType = ETrue;
       
   705 			TInt err(vmbx.GetVmbxAddressL(aNumber));
       
   706 	        if (err != KErrNone)
       
   707 	            {
       
   708 	            if (err != KErrNotFound ||
       
   709 	                    !vmbx.QueryAddressL(EVmbxNotDefinedQuery, aNumber))
       
   710 	                {
       
   711 	                result = EFalse;
       
   712 	                }
       
   713 	            }
       
   714         	}
       
   715 	        else
       
   716 	    	{
       
   717 	    	iType = EFalse;
       
   718 			TInt err(vmbx.GetVmbxNumber(aNumber));
       
   719 			if (err != KErrNone)
       
   720 				{
       
   721 				if (err != KErrNotFound ||
       
   722                     !vmbx.QueryNumberL(EVmbxNotDefinedQuery, aNumber))
       
   723 					{
       
   724 					result = EFalse;
       
   725 					}
       
   726 				}
       
   727 	    	}
       
   728        
       
   729         }
       
   730     CleanupStack::PopAndDestroy();  // It will call vmbx.Close()
       
   731     return result;
       
   732     }
       
   733     
       
   734 
       
   735 // ---------------------------------------------------------
       
   736 // CSpeedDialPrivate::ExVideoMailL  
       
   737 //
       
   738 // ---------------------------------------------------------
       
   739 //
       
   740     
       
   741   EXPORT_C TBool CSpeedDialPrivate::ExVideoMailL(TDes& aNumber)
       
   742     {
       
   743      //TInt iVmbxsupported(0);
       
   744     
       
   745     TBool result(ETrue);
       
   746 
       
   747 
       
   748     RVmbxNumber vmbx;
       
   749     CleanupClosePushL(vmbx); // So that Close() is called if a leave happens.
       
   750     
       
   751     if(vmbx.Open() == KErrNone)
       
   752     {
       
   753         
       
   754     
       
   755 //    if(vmbx.SelectTypeL( EVmbxCall )) 
       
   756     {
       
   757         
       
   758     
       
   759     iType = EVmbxVideo;
       
   760 
       
   761     TInt err2 = vmbx.GetVideoMbxNumber( aNumber );
       
   762 
       
   763 
       
   764 //#ifndef VIDEOMAILBOX_HIDDEN
       
   765 //ivmbxvariation->Get( KVideoMbxSupport, vmbxsupported );
       
   766 if(iVmbxsupported)
       
   767 {
       
   768 	
       
   769 
       
   770 	if (err2 == KErrNotFound)
       
   771 	{
       
   772 
       
   773 	aNumber.Zero();
       
   774 	if (err2 != KErrNotFound ||!vmbx.QueryVideoMbxNumberL(EVmbxNotDefinedQuery, aNumber))
       
   775 		{
       
   776 		result = EFalse;
       
   777 		}
       
   778 	}         
       
   779 	else
       
   780 	{
       
   781 	    result = ETrue;
       
   782 	}  
       
   783 }
       
   784 else
       
   785     //Number is present and can be called
       
   786     if(err2 != KErrNotFound)
       
   787     {
       
   788         result = ETrue;
       
   789     }
       
   790     else
       
   791     {
       
   792         result = EFalse;
       
   793     }
       
   794     
       
   795 
       
   796     }
       
   797 }
       
   798     CleanupStack::PopAndDestroy();  // It will call vmbx.Close()
       
   799     return result;
       
   800     }
       
   801 // CSpeedDialPrivate::Index
       
   802 //
       
   803 // ---------------------------------------------------------
       
   804 //
       
   805 EXPORT_C TInt CSpeedDialPrivate::Index(TInt aDial) const
       
   806     {
       
   807     return (aDial - 1);
       
   808     }
       
   809 
       
   810 // ---------------------------------------------------------
       
   811 // CSpeedDialPrivate::IconArray
       
   812 // An interface for accessing index data array.
       
   813 // ---------------------------------------------------------
       
   814 //
       
   815 EXPORT_C CArrayPtr<CGulIcon>* CSpeedDialPrivate::IconArray() const
       
   816     {
       
   817     return iIconArray;
       
   818     }
       
   819 
       
   820 // ---------------------------------------------------------
       
   821 // CSpeedDialPrivate::Contact
       
   822 // ---------------------------------------------------------
       
   823 //
       
   824  
       
   825 EXPORT_C MVPbkStoreContact* CSpeedDialPrivate::Contact(TInt aIndex)
       
   826 {
       
   827 	return (*iSdmArray)[aIndex].Contact();
       
   828 }
       
   829  
       
   830 // ---------------------------------------------------------
       
   831 // CSpeedDialPrivate::Number
       
   832 // An interface for accessing index data array
       
   833 // ---------------------------------------------------------
       
   834 //
       
   835 EXPORT_C TInt CSpeedDialPrivate::Number(TInt aIndex) const
       
   836     {
       
   837     return (aIndex + 1);
       
   838     }
       
   839     
       
   840 // ---------------------------------------------------------
       
   841 // CSpeedDialPrivate::PhoneNumber
       
   842 // An interface for accessing index data array.
       
   843 // ---------------------------------------------------------
       
   844 //
       
   845 EXPORT_C const TDesC& CSpeedDialPrivate::PhoneNumber(TInt aIndex) const
       
   846     {
       
   847     return (*iSdmArray)[aIndex].PhoneNumber();
       
   848     }
       
   849     
       
   850 // ---------------------------------------------------------
       
   851 // CSpeedDialPrivate::ThumbIndex
       
   852 // An interface for accessing index data array.
       
   853 // ---------------------------------------------------------
       
   854 //
       
   855 EXPORT_C TInt CSpeedDialPrivate::ThumbIndex(TInt aIndex) const
       
   856     {
       
   857     return (*iSdmArray)[aIndex].ThumbIndex();
       
   858     }
       
   859     
       
   860 // ---------------------------------------------------------
       
   861 // CSpeedDialPrivate::CreateGridDataL
       
   862 //
       
   863 // ---------------------------------------------------------
       
   864 //
       
   865 EXPORT_C TBool CSpeedDialPrivate::CreateGridDataL(
       
   866                 CAknGrid* aGrid, TBool aIndex )
       
   867     {
       
   868     iGrid = aGrid;
       
   869     if ( iGridUsed == EGridNoUse )
       
   870         {
       
   871         iGridUsed = EGridUse;
       
   872         }
       
   873 
       
   874     // The specified index is updated.
       
   875     if ( ( aIndex >= 0 ) && ( aIndex <= KMaxIndex ) )
       
   876         {
       
   877         return UpdateIndexDataL( aIndex );
       
   878         }
       
   879 
       
   880     CDesCArray* array = STATIC_CAST( CDesCArray*, aGrid->Model()->ItemTextArray() );
       
   881     if ( aIndex == KNullIndexData )
       
   882     	{
       
   883     	InitIndexDataL();
       
   884     	}
       
   885     TInt thumbCount = SetIconArrayL( iIconArray );
       
   886     if ( thumbCount > 0 )
       
   887         {
       
   888         SetOperationsL();
       
   889         }
       
   890 
       
   891     TKeyArrayFix key( TSpdiaIndexDataVPbk::OffsetValue( TSpdiaIndexDataVPbk::EIndex ), ECmpTInt );
       
   892     iSdmArray->Sort( key );
       
   893 
       
   894     CFormattedCellListBoxData* list = aGrid->ItemDrawer()->FormattedCellData();
       
   895     if ( list->IconArray() == NULL )
       
   896         {
       
   897         aGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL( iIconArray );
       
   898         }
       
   899 
       
   900     if ( thumbCount == 0 || State() != STATE_ASSIGN )
       
   901         {
       
   902         // fill number icon, avoid flicker
       
   903         array->Reset();
       
   904         SetItemDataL( *array );
       
   905         if ( thumbCount == 0 )
       
   906         	DrawNow();
       
   907         }
       
   908     return ETrue;
       
   909 
       
   910     }
       
   911 
       
   912 // ---------------------------------------------------------
       
   913 // CSpdiaContainer::SetLayout
       
   914 //
       
   915 // ---------------------------------------------------------
       
   916 //
       
   917 EXPORT_C void CSpeedDialPrivate::SetLayout(const TRect& aRect)
       
   918 	{
       
   919 	//Scalable UI.
       
   920 	if(AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
   921 	{
       
   922 	TRect			   	 mainPaneRect ;
       
   923     TRect 			   	 statusPaneRect;
       
   924     TAknLayoutRect     	 mainQdialRect;
       
   925 	TAknLayoutRect     	 gridQdialPaneRect;
       
   926 	TAknLayoutRect     	 cellQdialPaneRect;
       
   927     TAknWindowLineLayout cellQdialPane;
       
   928     TInt 				 varient =0;
       
   929 			
       
   930 	if (Layout_Meta_Data::IsLandscapeOrientation())
       
   931 	{
       
   932 	 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainPaneRect);
       
   933 	 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStatusPane,statusPaneRect);
       
   934 	 mainPaneRect.iTl = statusPaneRect.iTl;
       
   935 	 mainPaneRect.iBr.iY = mainPaneRect.iBr.iY - statusPaneRect.iTl.iY;
       
   936 	 varient =1;
       
   937 	}
       
   938 	else
       
   939 	{
       
   940 	 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainPaneRect);
       
   941 	 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStatusPane,statusPaneRect);
       
   942 	 mainPaneRect.iTl= statusPaneRect.iTl;
       
   943 	}
       
   944 		
       
   945 	SetRect(mainPaneRect);
       
   946 		
       
   947 	mainQdialRect.LayoutRect(mainPaneRect,AknLayoutScalable_Apps::main_qdial_pane().LayoutLine());
       
   948 	gridQdialPaneRect.LayoutRect(mainQdialRect.Rect(),AknLayoutScalable_Apps::grid_qdial_pane().LayoutLine());
       
   949 	cellQdialPaneRect.LayoutRect(gridQdialPaneRect.Rect(),AknLayoutScalable_Apps::cell_qdial_pane(0,0).LayoutLine());
       
   950     cellQdialPane = AknLayoutScalable_Apps::cell_qdial_pane_g4(varient).LayoutLine();
       
   951 			
       
   952 	TInt Cnt = 0;
       
   953 			
       
   954 	for(TInt rowSize=0;rowSize < 3; rowSize++)
       
   955 		{
       
   956 			for(TInt column=0;column < 3; column++)
       
   957 			{
       
   958 				icellLayout[Cnt].LayoutRect(gridQdialPaneRect.Rect(),AknLayoutScalable_Apps::cell_qdial_pane(column,rowSize).LayoutLine());	
       
   959 				Cnt ++ ;	
       
   960 			}
       
   961 				
       
   962 		}
       
   963 				
       
   964 
       
   965 	 (*iShadowLayout)[CSpdiaGridVPbk::EtnCIF].LayoutRect(cellQdialPaneRect.Rect(),cellQdialPane);
       
   966 
       
   967 	 (*iShadowLayout)[CSpdiaGridVPbk::EtnVGA90].LayoutRect(cellQdialPaneRect.Rect(),cellQdialPane);
       
   968 
       
   969 	 (*iShadowLayout)[CSpdiaGridVPbk::EtnVGA].LayoutRect(cellQdialPaneRect.Rect(),cellQdialPane);
       
   970 
       
   971 	 (*iShadowLayout)[CSpdiaGridVPbk::EtnCOM].LayoutRect(cellQdialPaneRect.Rect(),cellQdialPane);
       
   972 	      
       
   973 	            
       
   974 	}
       
   975 	else
       
   976 	{
       
   977 	TAknWindowLineLayout lScr = AknLayout::screen();
       
   978 	TAknWindowLineLayout lCtrlPane = AknLayout::control_pane(TRect( TPoint(lScr.il, lScr.it), TSize(lScr.iW, lScr.iH) ));
       
   979 	SetRect(TRect( TPoint(lScr.il, lScr.it), TSize(lScr.iW, lScr.iH - lCtrlPane.iH) ) );
       
   980 
       
   981     (*iShadowLayout)[CSpdiaGridVPbk::EtnCIF90].LayoutRect(aRect,AppLayout::Cell_pane_elements__qdial__Line_1());
       
   982     (*iShadowLayout)[CSpdiaGridVPbk::EtnCIF].LayoutRect(aRect,AppLayout::Cell_pane_elements__qdial__Line_4());
       
   983     (*iShadowLayout)[CSpdiaGridVPbk::EtnVGA90].LayoutRect(aRect,AppLayout::Cell_pane_elements__qdial__Line_7());
       
   984     (*iShadowLayout)[CSpdiaGridVPbk::EtnVGA].LayoutRect(aRect,AppLayout::Cell_pane_elements__qdial__Line_10());
       
   985     (*iShadowLayout)[CSpdiaGridVPbk::EtnCOM].LayoutRect(aRect,AppLayout::Cell_pane_elements__qdial__Line_13());
       
   986 		}
       
   987     }
       
   988 
       
   989 
       
   990 // ---------------------------------------------------------
       
   991 // CSpeedDialPrivate::VMBoxPosition
       
   992 //
       
   993 // ---------------------------------------------------------
       
   994 //
       
   995 EXPORT_C TInt CSpeedDialPrivate::VMBoxPosition() const
       
   996     {
       
   997     return KVoiceMail;
       
   998     }
       
   999     
       
  1000 // ---------------------------------------------------------
       
  1001 // CSpeedDialPrivate::VdoMBoxPosition
       
  1002 //
       
  1003 // ---------------------------------------------------------
       
  1004 //
       
  1005 EXPORT_C TInt CSpeedDialPrivate::VdoMBoxPosition() const
       
  1006     {
       
  1007     if ( !iVmbxsupported )
       
  1008         {
       
  1009         // Video Mailbox feature is disabled
       
  1010         return KErrNone;
       
  1011         }
       
  1012    
       
  1013     if ( iVmbxkeypos )
       
  1014         {
       
  1015         return iVmbxkeypos - 1;
       
  1016         }
       
  1017 
       
  1018     return KErrNone;
       
  1019     }
       
  1020 //CSpeedDialPrivate::SpdIconIndex
       
  1021 // An interface for accessing index data array.
       
  1022 // ---------------------------------------------------------
       
  1023 //
       
  1024 EXPORT_C TInt CSpeedDialPrivate::SpdIconIndex(TInt aIndex) const
       
  1025     {
       
  1026     return (*iSdmArray)[aIndex].IconIndex();
       
  1027     }
       
  1028     
       
  1029     
       
  1030 // ---------------------------------------------------------
       
  1031 // CSpeedDialPrivate::DeleteIconArray
       
  1032 // Deletes the old icons.
       
  1033 // ---------------------------------------------------------
       
  1034 EXPORT_C void CSpeedDialPrivate::DeleteIconArray()
       
  1035 	{
       
  1036 	 if(iIconArray)
       
  1037 		 {
       
  1038 			iIconArray->ResetAndDestroy();
       
  1039 			delete iIconArray;
       
  1040 			iIconArray = NULL;
       
  1041 		 }
       
  1042 	}
       
  1043 	
       
  1044 // ---------------------------------------------------------
       
  1045 // CSpeedDialPrivate::ReloadIconArray
       
  1046 // Reloads the new skin icons.
       
  1047 // ---------------------------------------------------------
       
  1048 EXPORT_C void CSpeedDialPrivate::ReloadIconArray()
       
  1049 {
       
  1050 	TRAPD(err,
       
  1051 	{
       
  1052 		if (iGrid)
       
  1053 		{
       
  1054 			if(NULL == iIconArray)
       
  1055 			{
       
  1056 		    	iIconArray = new (ELeave)CAknIconArray(iSdmCount);
       
  1057 		    }
       
  1058 		
       
  1059             if ( SetIconArrayL( iIconArray ) > 0 )
       
  1060             {
       
  1061             	SetOperationsL();
       
  1062             }
       
  1063         
       
  1064             iGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL( iIconArray );
       
  1065 		}
       
  1066 	});
       
  1067 	
       
  1068 	//Just to avoid warning..
       
  1069 	if(err)
       
  1070 	{
       
  1071 		
       
  1072 	}
       
  1073 }
       
  1074 
       
  1075 // ---------------------------------------------------------
       
  1076 // CSpeedDialPrivate::SetIconArrayL
       
  1077 //
       
  1078 // ---------------------------------------------------------
       
  1079 TInt CSpeedDialPrivate::SetIconArrayL(CArrayPtrFlat<CGulIcon>* aArray)
       
  1080     {
       
  1081     if ( aArray != NULL )
       
  1082         {
       
  1083         aArray->ResetAndDestroy();
       
  1084         }
       
  1085     else
       
  1086         {
       
  1087         return 0;
       
  1088         }
       
  1089 
       
  1090     CreateIndexIconsL( aArray );
       
  1091     CreateFieldIconsL( aArray );     
       
  1092 
       
  1093 	TInt existThumb = 0;
       
  1094 	const TInt count = iSdmArray->Count();
       
  1095     for (TInt index(0); index < count; index++)
       
  1096         {
       
  1097         if (CreateIndexIconL(index, (*iSdmArray)[index], existThumb > 0? EFalse: ETrue))
       
  1098             {
       
  1099             ++existThumb;
       
  1100             }
       
  1101         }
       
  1102 
       
  1103     return existThumb;
       
  1104     }
       
  1105 
       
  1106 // ---------------------------------------------------------
       
  1107 // CSpeedDialPrivate::CreateIndexIconsL
       
  1108 //
       
  1109 // ---------------------------------------------------------
       
  1110 TInt CSpeedDialPrivate::CreateIndexIconsL( CArrayPtrFlat<CGulIcon>* aArray )
       
  1111 	{
       
  1112 	CFbsBitmap* bitmap,*mask;
       
  1113 	bitmap = NULL;
       
  1114 	mask= NULL;
       
  1115 	MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
  1116 
       
  1117     for (TInt index(0); index < iSdmArray->Count(); index++)
       
  1118         {
       
  1119 		if(index == 0)
       
  1120 		    {
       
  1121 		    TUid uidVmbx;
       
  1122 		    uidVmbx.iUid =KVmbxUid;
       
  1123 		    AknsUtils::CreateAppIconLC( skinInstance,uidVmbx, EAknsAppIconTypeContext,bitmap ,mask);		
       
  1124 		    CleanupStack::Pop(2);
       
  1125 		    }
       
  1126 		else
       
  1127 		   {
       
  1128 		 	if(User::Language() == ELangHindi)
       
  1129 		 	    {
       
  1130 		 		AknsUtils::CreateIconL(skinInstance, (*iDialSkinBmp)[index],bitmap,mask,iBmpPath,iDialHindiBmp[index],  iDialHindiBmpMask[index] );	
       
  1131 		 	    }
       
  1132 		 	else
       
  1133 		 	    {
       
  1134 		 	 	AknsUtils::CreateIconL(skinInstance, (*iDialSkinBmp)[index],bitmap,mask,iBmpPath,iDialBmp[index],  iDialBmpMask[index] );	
       
  1135 		 	    }
       
  1136 		    }
       
  1137 		
       
  1138 		CGulIcon* icon = CGulIcon::NewL(bitmap,mask);
       
  1139 	    CleanupStack::PushL(icon);
       
  1140 	    aArray->AppendL(icon);
       
  1141 	    CleanupStack::Pop(); // icon
       
  1142         }
       
  1143     
       
  1144 	}
       
  1145 
       
  1146 // ---------------------------------------------------------
       
  1147 // CSpeedDialPrivate::VoiceMailTypeL	
       
  1148 //
       
  1149 // ---------------------------------------------------------
       
  1150 //
       
  1151 EXPORT_C TInt CSpeedDialPrivate::VoiceMailType()
       
  1152     {
       
  1153     return iType;
       
  1154     }
       
  1155     
       
  1156 // ---------------------------------------------------------
       
  1157 // CSpeedDialPrivate::GetSpdCtrlLastError()
       
  1158 // retuns last error 
       
  1159 // ---------------------------------------------------------
       
  1160 //	
       
  1161 EXPORT_C TInt CSpeedDialPrivate::GetSpdCtrlLastError()
       
  1162     {
       
  1163      return iError;
       
  1164  	}
       
  1165 	
       
  1166 // ---------------------------------------------------------
       
  1167 // CSpdiaContainer::Draw
       
  1168 //
       
  1169 // ---------------------------------------------------------
       
  1170 //
       
  1171 void CSpeedDialPrivate::Draw(const TRect& /*aRect*/) const
       
  1172     {
       
  1173     CWindowGc& gc = SystemGc();
       
  1174    AknsDrawUtils::Background(
       
  1175        AknsUtils::SkinInstance(),
       
  1176        AknsDrawUtils::ControlContext(this),
       
  1177        this,
       
  1178        gc,
       
  1179        Rect() );
       
  1180     }
       
  1181     
       
  1182 // ---------------------------------------------------------
       
  1183 // CSpeedDialPrivate::SizeChanged()
       
  1184 //
       
  1185 // ---------------------------------------------------------
       
  1186 //
       
  1187 void CSpeedDialPrivate::SizeChanged()
       
  1188 {
       
  1189 		iBgContext->SetRect( Rect() );
       
  1190 }
       
  1191 
       
  1192 // ---------------------------------------------------------
       
  1193 // CSpeedDialPrivate::MopSupplyObject() 
       
  1194 // Pass skin information if need.
       
  1195 // ---------------------------------------------------------
       
  1196 //
       
  1197 TTypeUid::Ptr CSpeedDialPrivate::MopSupplyObject(TTypeUid aId)
       
  1198 {
       
  1199     if(aId.iUid == MAknsControlContext::ETypeId)
       
  1200     {
       
  1201         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
  1202     }
       
  1203     return CCoeControl::MopSupplyObject( aId );
       
  1204 }	
       
  1205 	
       
  1206 // ---------------------------------------------------------
       
  1207 // CSpeedDialPrivate::NumberType
       
  1208 // An interface for accessing phone number type.
       
  1209 // Number types are defined in PbkFields.hrh.
       
  1210 // ---------------------------------------------------------
       
  1211 //
       
  1212 EXPORT_C TInt CSpeedDialPrivate::NumberType(TInt aIndex) const
       
  1213 {
       
  1214 	TInt retVal = ESpDialPbkFieldIdNone;
       
  1215 	TInt fieldId = -1;	
       
  1216 	MVPbkStoreContactField* field = (*iSdmArray)[aIndex].Field();
       
  1217 	
       
  1218 	if(field)
       
  1219 	{
       
  1220 		fieldId = field->BestMatchingFieldType()->FieldTypeResId();
       
  1221 		
       
  1222 		switch(fieldId)
       
  1223 		{
       
  1224 			case R_VPBK_FIELD_TYPE_VIDEONUMBERHOME:
       
  1225 			case R_VPBK_FIELD_TYPE_VIDEONUMBERWORK:
       
  1226 			case R_VPBK_FIELD_TYPE_VIDEONUMBERGEN:
       
  1227 				retVal = ESpDialPbkFieldIdPhoneNumberVideo;
       
  1228 				break;
       
  1229 			case R_VPBK_FIELD_TYPE_VOIPHOME:
       
  1230 			case R_VPBK_FIELD_TYPE_VOIPWORK:
       
  1231 			case R_VPBK_FIELD_TYPE_VOIPGEN:
       
  1232 			case R_VPBK_FIELD_TYPE_IMPP:
       
  1233 				retVal = ESpDialPbkFieldIdVOIP;
       
  1234 				break;
       
  1235 			default:
       
  1236 				retVal = ESpDialPbkFieldIdPhoneGeneral;
       
  1237 		}
       
  1238 	}
       
  1239     return retVal;
       
  1240 }
       
  1241 
       
  1242 // ---------------------------------------------------------
       
  1243 // CSpeedDialPrivate::DrawShadow
       
  1244 //
       
  1245 // ---------------------------------------------------------
       
  1246 //
       
  1247 void CSpeedDialPrivate::DrawShadow(CWindowGc& aGc) const
       
  1248     {
       
  1249     //TSize size(cell_spdia_item_w, cell_spdia_item_h);
       
  1250 	//Scalable UI.
       
  1251 	TAknWindowLineLayout area;
       
  1252 	if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
  1253 	{
       
  1254 	 area = AknLayoutScalable_Apps::cell_qdial_pane(0,0).LayoutLine();           
       
  1255 	}
       
  1256 	else
       
  1257 	{
       
  1258 	 area = AppLayout::cell_qdial_pane(0,0);
       
  1259 	}
       
  1260 	
       
  1261 	TSize size(area.iW, area.iH);
       
  1262     aGc.SetPenColor(AKN_LAF_COLOR(SDM_TN_SHADOW_COROL));
       
  1263     TInt count(iSdmArray->Count());
       
  1264 	//TRect rect(TPoint(spdia_main_pane_grid_l, spdia_main_pane_grid_t), size);
       
  1265 	//Scalable UI
       
  1266 	if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
  1267 	{
       
  1268 	 area = AknLayoutScalable_Apps::grid_qdial_pane().LayoutLine();
       
  1269 	}
       
  1270 	else
       
  1271 	{
       
  1272 	 area = AppLayout::Speed_Dial_descendants_Line_1();
       
  1273 	}
       
  1274     TRect rect(TPoint(area.il, area.it), size);
       
  1275     for (TInt i(0); i < count; ++i)
       
  1276         {
       
  1277         if (ThumbIndex(i) >= 0)
       
  1278             {
       
  1279             TInt type(ThumbType(i));
       
  1280             TRect rc((*iShadowLayout)[type].Rect());
       
  1281             if (type == CSpdiaGridVPbk::EtnCOM)
       
  1282                 {
       
  1283                 TSize image(ThumbSize(i));
       
  1284                 image.iWidth = Min(image.iWidth, rc.Width());
       
  1285                 image.iHeight = Min(image.iHeight, rc.Height());
       
  1286                 rc = TRect(TPoint(0,0), image);
       
  1287                 // Correct the x and y to the accurate values.
       
  1288                 TInt x(Max(0, (size.iWidth - image.iWidth) / 2) + 3);
       
  1289                 TInt y(Max(0, (size.iHeight - image.iHeight) / 2) - 2);
       
  1290                 rc.Move(x, y);
       
  1291                 }
       
  1292             rc.Move(rect.iTl.iX, rect.iTl.iY);
       
  1293             aGc.DrawRect(rc);
       
  1294             }
       
  1295         rect.Move(size.iWidth, 0);
       
  1296         if (((i + 1)/ KCellColCount) * KCellRowCount == i + 1)
       
  1297             {
       
  1298             rect.Move(-(KCellColCount * size.iWidth), size.iHeight);
       
  1299             }
       
  1300         }
       
  1301     }
       
  1302 
       
  1303 // ---------------------------------------------------------
       
  1304 // CSpeedDialPrivate::CheckingIfPopUpNeededL
       
  1305 // Internal rutine to check if pop up has to be shown		
       
  1306 // to enable the One-Key-Dialling setting.
       
  1307 // ---------------------------------------------------------
       
  1308 //
       
  1309 
       
  1310 EXPORT_C TBool CSpeedDialPrivate::CheckingIfPopUpNeededL()
       
  1311     {
       
  1312     TBool gridEmpty( ETrue );
       
  1313     TInt  gridIndex( 1 );
       
  1314     TInt value;
       
  1315     TBool result( ETrue );
       
  1316 
       
  1317     CRepository* repository = CRepository::NewL( KCRUidTelephonySettings );
       
  1318     repository->Get( KSettingsOneKeyDialling, value );
       
  1319 
       
  1320     if ( value == 0 )
       
  1321         {
       
  1322         while ( ( gridIndex < 9 ) && gridEmpty )
       
  1323             {
       
  1324             if ( ( *iSdmArray )[ gridIndex ].Contact() != NULL )
       
  1325                 {
       
  1326                 gridEmpty = EFalse;
       
  1327                 }
       
  1328             ++gridIndex;
       
  1329             }
       
  1330         result = gridEmpty;	
       
  1331         }
       
  1332     else
       
  1333         {
       
  1334         result = EFalse;
       
  1335         }
       
  1336     delete repository;
       
  1337     return result;
       
  1338     }
       
  1339 		
       
  1340 // ---------------------------------------------------------
       
  1341 // CSpeedDialPrivate::Pbk2ImageGetComplete
       
  1342 //
       
  1343 // ---------------------------------------------------------
       
  1344 //
       
  1345 void CSpeedDialPrivate::Pbk2ImageGetComplete
       
  1346         (MPbk2ImageOperation& aOperation, CFbsBitmap* aBitmap)
       
  1347  {
       
  1348 	TRAP_IGNORE(Pbk2ImageGetCompleteL(aOperation, aBitmap));
       
  1349  }
       
  1350  
       
  1351 // ---------------------------------------------------------
       
  1352 // CSpeedDialPrivate::Pbk2ImageGetCompleteL
       
  1353 //
       
  1354 // ---------------------------------------------------------
       
  1355 //
       
  1356 void CSpeedDialPrivate::Pbk2ImageGetCompleteL
       
  1357         (MPbk2ImageOperation& aOperation, CFbsBitmap* aBitmap)
       
  1358  {
       
  1359  	
       
  1360     //for async call	 
       
  1361     TInt index(HasImageOperation(aOperation));
       
  1362     
       
  1363     if (index != KNullIndexData)
       
  1364     {
       
  1365 		if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
  1366 			{
       
  1367 			CAknIcon* icon = CAknIcon::NewL();
       
  1368 			icon->SetBitmap(aBitmap);
       
  1369 
       
  1370 			// create mask
       
  1371 			CFbsBitmap* mask = new (ELeave) CFbsBitmap();
       
  1372 
       
  1373 			TSize size = aBitmap->SizeInPixels();
       
  1374 			mask->Create(size,EGray2);
       
  1375 
       
  1376 			CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
       
  1377 			CleanupStack::PushL( fbsBitGc );
       
  1378 			CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL( mask );
       
  1379 			CleanupStack::PushL( bmpDevice );
       
  1380 			bmpDevice->Resize( size );
       
  1381 			fbsBitGc->Activate( bmpDevice );
       
  1382 
       
  1383 			fbsBitGc->SetPenStyle(CGraphicsContext::ENullPen);
       
  1384 			fbsBitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  1385 
       
  1386 			fbsBitGc->SetBrushColor(KRgbBlack); 
       
  1387 			fbsBitGc->DrawRect( TRect( size ) );
       
  1388 
       
  1389 			CleanupStack::PopAndDestroy( 2, fbsBitGc ); // bmpDevice and fbsBitGc
       
  1390 
       
  1391 			icon->SetMask(mask);
       
  1392 
       
  1393 			// this creates both scalable icon and mask
       
  1394 			CAknIcon* scaledIcon = AknIconUtils::CreateIconL(icon);
       
  1395 
       
  1396 			TSize thumbnailSize = GetThumbnailSize();
       
  1397 
       
  1398 			AknIconUtils::SetSize(scaledIcon->Bitmap(),thumbnailSize,EAspectRatioPreservedAndUnusedSpaceRemoved);
       
  1399 			AknIconUtils::SetSize(scaledIcon->Mask(),thumbnailSize,EAspectRatioPreservedAndUnusedSpaceRemoved);
       
  1400 
       
  1401 			CFbsBitmap* bmp = new (ELeave) CFbsBitmap();
       
  1402 			CFbsBitmap* msk = new (ELeave) CFbsBitmap();
       
  1403 			TInt err = msk->Duplicate( scaledIcon->Mask()->Handle() ); 
       
  1404 			TInt err1 = bmp->Duplicate( scaledIcon->Bitmap()->Handle() );			
       
  1405 
       
  1406             delete ( *iIconArray )[index];
       
  1407             ( *iIconArray )[index] = NULL;
       
  1408             ( *iIconArray )[index] = CGulIcon::NewL( bmp, msk );
       
  1409             // set the text array of grid
       
  1410             ( *iSdmArray )[index].SetThumbIndex( index, bmp );
       
  1411             delete scaledIcon;
       
  1412             }       
       
  1413             
       
  1414         else
       
  1415             {
       
  1416             // set the scaled bitmap to the array of icons
       
  1417             delete ( *iIconArray )[index];
       
  1418             ( *iIconArray )[index] = NULL;
       
  1419             ( *iIconArray )[index] = CGulIcon::NewL( aBitmap );
       
  1420             // set the text array of grid
       
  1421             ( *iSdmArray )[index].SetThumbIndex( index, aBitmap );
       
  1422              }
       
  1423 
       
  1424 	       if ( ( *iSdmArray )[index].LastThumb() )
       
  1425 	            {
       
  1426 	            CDesCArray* array = STATIC_CAST( CDesCArray*, iGrid->Model()->ItemTextArray() );
       
  1427 	            array->Reset();
       
  1428 	            SetItemDataL( *array );
       
  1429 	            DrawNow();
       
  1430 	            }
       
  1431 	        delete &aOperation;
       
  1432 	        ( *iSdmArray )[index].SetImageOperation( NULL ); 
       
  1433 	    }
       
  1434 	
       
  1435     iOperationComplete = ETrue;
       
  1436     Release();
       
  1437 	}
       
  1438 
       
  1439 	
       
  1440 // ---------------------------------------------------------
       
  1441 // CSpeedDialPrivate::Pbk2ImageGetFailed
       
  1442 //
       
  1443 // ---------------------------------------------------------
       
  1444 //
       
  1445 void CSpeedDialPrivate::Pbk2ImageGetFailed
       
  1446         ( MPbk2ImageOperation& aOperation,
       
  1447         TInt aError )
       
  1448     {
       
  1449     iError = aError;
       
  1450     TInt index( HasImageOperation( aOperation ) );
       
  1451     if ( index != KNullIndexData )
       
  1452         {
       
  1453         delete &aOperation;
       
  1454         ( *iSdmArray )[index].SetImageOperation( NULL );
       
  1455         if ( ( *iSdmArray )[index].LastThumb() )
       
  1456             {
       
  1457             CDesCArray* array = STATIC_CAST( CDesCArray*, iGrid->Model()->ItemTextArray() );
       
  1458             array->Reset();
       
  1459             TRAP_IGNORE( SetItemDataL( *array ) );
       
  1460             DrawNow();
       
  1461             }
       
  1462         }
       
  1463     iOperationComplete = ETrue;
       
  1464     Release();
       
  1465     }
       
  1466 
       
  1467 
       
  1468 // ---------------------------------------------------------
       
  1469 // CSpeedDialPrivate::HasImageOperation
       
  1470 //
       
  1471 // ---------------------------------------------------------
       
  1472 //
       
  1473 TInt CSpeedDialPrivate::HasImageOperation(MPbk2ImageOperation& aOperation)
       
  1474 {
       
  1475 	TInt index = KNullIndexData;
       
  1476 	for(TInt count =0; count < iSdmArray->Count() && index == KNullIndexData; ++count)
       
  1477 	{
       
  1478 	    if ((*iSdmArray)[count].ImageOperation() == &aOperation)
       
  1479         {
       
  1480              index = count;
       
  1481         }		
       
  1482 	}
       
  1483 	return index;
       
  1484 }
       
  1485 
       
  1486 // ---------------------------------------------------------
       
  1487 // CSpeedDialPrivate::SetDetails
       
  1488 //
       
  1489 // ---------------------------------------------------------
       
  1490 //
       
  1491 void CSpeedDialPrivate::SetDetails(TInt aIndex)
       
  1492 {
       
  1493 	MVPbkStoreContactField* field = (*iSdmArray)[aIndex].Field();
       
  1494 	
       
  1495 	if(field != NULL)
       
  1496 	{
       
  1497     HBufC* number = NULL;
       
  1498     TRAP_IGNORE(
       
  1499             {
       
  1500             TVPbkFieldStorageType dataType = field->FieldData().DataType();
       
  1501             
       
  1502             switch( dataType )
       
  1503                 {
       
  1504                 case EVPbkFieldStorageTypeText:
       
  1505                     {
       
  1506                     const MVPbkContactFieldTextData& data = MVPbkContactFieldTextData::Cast( field->FieldData() );
       
  1507                     number = data.Text().AllocLC();
       
  1508                     break;
       
  1509                     }
       
  1510                 case EVPbkFieldStorageTypeUri:
       
  1511                     {
       
  1512                     const MVPbkContactFieldUriData& data = MVPbkContactFieldUriData::Cast( field->FieldData() );
       
  1513                     number = data.Text().AllocLC();
       
  1514                     break;
       
  1515                     }
       
  1516                 }
       
  1517         
       
  1518             if (number != NULL)
       
  1519 				{
       
  1520 				//store the phone numbers in a array and cast those to TPhCltTelephoneNumber.
       
  1521             	(*iSdmArray)[aIndex].SetPhoneNumber(*number);		           
       
  1522             	CleanupStack::PopAndDestroy( number );
       
  1523 				}
       
  1524 			
       
  1525 			//Push
       
  1526             const MVPbkFieldType* fieldType = field->BestMatchingFieldType();
       
  1527             TInt iconindex = FindIconIndex(fieldType->FieldTypeResId(), field );
       
  1528             (*iSdmArray)[aIndex].SetIconIndex(iconindex);
       
  1529     
       
  1530             //No need to fetch thumbnail now...will be updated while grid is
       
  1531             // drawn
       
  1532             (*iSdmArray)[aIndex].SetThumbIndex(-1,NULL);	
       
  1533             }
       
  1534         );	
       
  1535 	}
       
  1536 	    
       
  1537 }
       
  1538 // ---------------------------------------------------------
       
  1539 // CSpeedDialPrivate::AttributeOperationComplete
       
  1540 //
       
  1541 // ---------------------------------------------------------
       
  1542 //
       
  1543 
       
  1544 void CSpeedDialPrivate::AttributeOperationComplete( MVPbkContactOperationBase& aOperation)
       
  1545 {
       
  1546 
       
  1547     TInt index = HasOperation(&aOperation);
       
  1548      
       
  1549      //for async call
       
  1550     if (index != KNullIndexData)
       
  1551     {
       
  1552         TSpdiaIndexDataVPbk::TOperation operation = (*iSdmArray)[index].Operation();    
       
  1553         //MVPbkStoreContactField* field = (*iSdmArray)[index].Field();
       
  1554         
       
  1555         switch(operation)
       
  1556         {
       
  1557             case TSpdiaIndexDataVPbk::OPERATION_ASSIGN:
       
  1558             
       
  1559                 TRAPD(err,
       
  1560                 {
       
  1561                                 
       
  1562                 HBufC* prompt = StringLoader::LoadLC(R_SPDIA_TEXT_KEY_ASSIGNED, index+1, iCoeEnv);
       
  1563                 CAknConfirmationNote* note = new (ELeave)CAknConfirmationNote();
       
  1564                 note->ExecuteLD(*prompt);
       
  1565                 
       
  1566                 CleanupStack::PopAndDestroy(prompt);
       
  1567                 });
       
  1568                 if(err == KErrNone)
       
  1569                 {
       
  1570                     SetDetails(index);
       
  1571                 }
       
  1572             
       
  1573             break;
       
  1574             
       
  1575             case TSpdiaIndexDataVPbk::OPERATION_REMOVE:
       
  1576                 (*iSdmArray)[index].Reset();                
       
  1577             
       
  1578             break;
       
  1579             
       
  1580             case TSpdiaIndexDataVPbk::OPERATION_NONE:
       
  1581             
       
  1582             //Error Handling
       
  1583             
       
  1584             break;
       
  1585                     
       
  1586             
       
  1587         }
       
  1588         
       
  1589         iOperationComplete = ETrue;
       
  1590         Release();
       
  1591             
       
  1592     }
       
  1593     
       
  1594   //  CleanupStack::PopAndDestroy();     
       
  1595 }
       
  1596 
       
  1597 // ---------------------------------------------------------
       
  1598 // CSpeedDialPrivate::AttributeOperationFailed
       
  1599 //
       
  1600 // ---------------------------------------------------------
       
  1601 //
       
  1602 void CSpeedDialPrivate::AttributeOperationFailed(MVPbkContactOperationBase& aOperation, TInt aError) 
       
  1603 {
       
  1604 	
       
  1605 	TInt index(HasOperation(&aOperation));
       
  1606 	
       
  1607 	if (index != KNullIndexData)
       
  1608 	{
       
  1609 		TSpdiaIndexDataVPbk::TOperation operation = (*iSdmArray)[index].Operation();	
       
  1610 		
       
  1611 		switch(operation)
       
  1612 		{
       
  1613 			case TSpdiaIndexDataVPbk::OPERATION_ASSIGN:
       
  1614 				(*iSdmArray)[index].Reset();
       
  1615 			break;
       
  1616 			
       
  1617 			case TSpdiaIndexDataVPbk::OPERATION_REMOVE:
       
  1618 				(*iSdmArray)[index].Reset();
       
  1619 			break;
       
  1620 			
       
  1621 			default:
       
  1622 			 	delete &aOperation;
       
  1623 		}
       
  1624 		iError = aError;
       
  1625 		iOperationComplete = ETrue;
       
  1626 		Release();
       
  1627 		
       
  1628 	}
       
  1629 			
       
  1630 
       
  1631 }
       
  1632 
       
  1633 
       
  1634 // ---------------------------------------------------------
       
  1635 // CSpeedDialPrivate::HasOperation
       
  1636 //
       
  1637 // ---------------------------------------------------------
       
  1638 //
       
  1639 TInt CSpeedDialPrivate::HasOperation(MVPbkContactOperationBase* aContactOpertion)
       
  1640 {
       
  1641 	TInt i=0, index = KNullIndexData;		
       
  1642 	for(i=0;i<iSdmArray->Count() && index == KNullIndexData;++i)
       
  1643 	{
       
  1644 		if ((*iSdmArray)[i].HasOperation(aContactOpertion))
       
  1645 		{
       
  1646 			index =i;
       
  1647 		}
       
  1648 	}
       
  1649 	
       
  1650 	return index;
       
  1651 }
       
  1652 
       
  1653 
       
  1654 // ---------------------------------------------------------
       
  1655 // CSpeedDialPrivate::EMail
       
  1656 //
       
  1657 // ---------------------------------------------------------
       
  1658 //
       
  1659 EXPORT_C HBufC* CSpeedDialPrivate::EMail( MVPbkStoreContact* aContact )
       
  1660     {  
       
  1661 
       
  1662         TUint fetchFlags = 0;
       
  1663         iMail = NULL;
       
  1664         iFetchmail = ETrue;
       
  1665         // Set service data
       
  1666         TAiwSingleItemSelectionDataV3 data;
       
  1667 
       
  1668         data.SetFlags(fetchFlags);
       
  1669         data.SetCommAddressSelectType(EAiwCommEmailEditor);
       
  1670         TRAP_IGNORE(
       
  1671                 {
       
  1672         CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
  1673         inParamList.AppendL(TAiwGenericParam(EGenericParamContactSelectionData,
       
  1674           TAiwVariant(TAiwSingleItemSelectionDataV3Pckg(data))));
       
  1675 
       
  1676         MVPbkContactLinkArray* linkArray = NULL;
       
  1677         CVPbkContactLinkArray* array = CVPbkContactLinkArray::NewLC();
       
  1678         MVPbkContactLink* ContactLink = aContact->CreateLinkLC();
       
  1679         CleanupStack::Pop();
       
  1680         array->AppendL(ContactLink);
       
  1681         linkArray = array;
       
  1682       
       
  1683         HBufC8* PackLink = linkArray->PackLC();
       
  1684         inParamList.AppendL(TAiwGenericParam(EGenericParamContactLinkArray,
       
  1685           TAiwVariant(*PackLink)));
       
  1686         CleanupStack::PopAndDestroy();//PackLink
       
  1687         CleanupStack::PopAndDestroy();//linkArray
       
  1688         CAiwGenericParamList& outParamList = iServiceHandler->OutParamListL();
       
  1689         iServiceHandler->ExecuteServiceCmdL(KAiwCmdSelect, inParamList,
       
  1690                 outParamList, 0, this);
       
  1691                 }
       
  1692                     );
       
  1693         iFetchmailComplete = EFalse;
       
  1694         // Wait till the contact is selected
       
  1695         while ( !iFetchmailComplete )
       
  1696         {
       
  1697         WaitFetchMail();
       
  1698         }
       
  1699         iFetchmail = EFalse;
       
  1700         return iMail;
       
  1701     }
       
  1702 
       
  1703 // ---------------------------------------------------------
       
  1704 // CSpeedDialPrivate::SetSpeedDialIndexL
       
  1705 //
       
  1706 // ---------------------------------------------------------
       
  1707 //
       
  1708 void CSpeedDialPrivate::SetSpeedDialIndexL(MVPbkStoreContact* aContact)
       
  1709 {
       
  1710 	TInt count =0;
       
  1711 	TInt index = KNullIndexData;
       
  1712 	
       
  1713 	//	Do a linear search to find which is the speeddial index 
       
  1714 	// 	stored in this field.
       
  1715 	for(count =0; count<KArraySize && index ==KNullIndexData; ++count)
       
  1716 	{
       
  1717 		// Compare with every speeddial attribute
       
  1718 		iSpeedDial->SetIndex(count+1);
       
  1719 		
       
  1720 		//If the index is not assigned already..
       
  1721 		if((*iSdmArray)[count].Contact() == NULL)
       
  1722 		{
       
  1723 			MVPbkStoreContactFieldCollection* fieldCollection = iAttributeManager->FindFieldsWithAttributeLC(
       
  1724                 						*(iSpeedDial), *aContact); 
       
  1725 			if(fieldCollection && (fieldCollection->FieldCount() > 0))
       
  1726 			{
       
  1727 				index = count;
       
  1728 				
       
  1729 				MVPbkStoreContactField& field = fieldCollection->FieldAt(0);
       
  1730 				
       
  1731 				(*iSdmArray)[index].SetContactLink(field.CreateLinkLC());
       
  1732 				(*iSdmArray)[index].SetContact(aContact);
       
  1733 				CleanupStack::Pop();
       
  1734 				
       
  1735 	            TVPbkFieldStorageType dataType = field.FieldData().DataType();
       
  1736 	            HBufC* number = NULL;
       
  1737 	            switch( dataType )
       
  1738                 {
       
  1739 	                case EVPbkFieldStorageTypeText:
       
  1740                     {
       
  1741 	                    const MVPbkContactFieldTextData& data = MVPbkContactFieldTextData::Cast( field.FieldData() );
       
  1742 	                    number = data.Text().AllocLC();
       
  1743 	                    break;
       
  1744                     }
       
  1745 	                case EVPbkFieldStorageTypeUri:
       
  1746                     {
       
  1747 	                    const MVPbkContactFieldUriData& data = MVPbkContactFieldUriData::Cast( field.FieldData() );
       
  1748 	                    number = data.Text().AllocLC();
       
  1749 	                    break;
       
  1750                     }
       
  1751                 }
       
  1752 				
       
  1753 			    if ( number != NULL )
       
  1754                 {
       
  1755 					TPhCltTelephoneNumber phonenumber(*number);
       
  1756                     phonenumber.Trim();
       
  1757 					CleanupStack::PopAndDestroy( number );
       
  1758 					//store the phone numbers in a array and cast those to TPhCltTelephoneNumber.
       
  1759                     if(phonenumber.Length() > 0)
       
  1760                     {
       
  1761                         (*iSdmArray)[index].SetPhoneNumber(phonenumber);
       
  1762                     }
       
  1763                 }
       
  1764                 else
       
  1765                 {
       
  1766                     //Remove SpeedDial
       
  1767                 }
       
  1768 			}
       
  1769 			
       
  1770 			CleanupStack::PopAndDestroy(); // Pop and Destroy FieldCollection
       
  1771 			
       
  1772 		}
       
  1773 	}
       
  1774 	//Delete if we are not using that contact..
       
  1775 	if(KNullIndexData == index)
       
  1776 	{
       
  1777 		delete aContact;
       
  1778 	}
       
  1779 	
       
  1780 }
       
  1781 	
       
  1782 // ---------------------------------------------------------
       
  1783 // CSpeedDialPrivate::VPbkSingleContactOperationComplete()
       
  1784 //
       
  1785 // ---------------------------------------------------------
       
  1786 void CSpeedDialPrivate::VPbkSingleContactOperationComplete( MVPbkContactOperationBase& aOperation, 
       
  1787 													MVPbkStoreContact* aContact)
       
  1788 {
       
  1789 
       
  1790  	if (iState == STATE_INITIAL)
       
  1791  	{
       
  1792  		TRAP_IGNORE(SetSpeedDialIndexL(aContact));
       
  1793  		iRetrieveComplete = ETrue;
       
  1794 		Release();
       
  1795  	}
       
  1796  	else if(iState == STATE_CONTACTCHANGE)
       
  1797  	{
       
  1798  		iContact = aContact;
       
  1799  		iRetrieveComplete = ETrue;
       
  1800 		Release();
       
  1801  	}
       
  1802  	else
       
  1803  	{
       
  1804 		
       
  1805 		TInt index = HasOperation(&aOperation);
       
  1806 		
       
  1807 		if (index != KNullIndexData)
       
  1808 		{
       
  1809 			TSpdiaIndexDataVPbk::TOperation operation = (*iSdmArray)[index].Operation();
       
  1810 			if(TSpdiaIndexDataVPbk::OPERATION_ASSIGN == operation)
       
  1811 			{	
       
  1812 				
       
  1813 				// Store the contact and field in corresponding index
       
  1814 				(*iSdmArray)[index].SetContact(aContact);
       
  1815 				(*iSdmArray)[index].SetContactLink(iContactLink);
       
  1816 				iRetrieveComplete = ETrue;
       
  1817 				Release();
       
  1818 						
       
  1819 			}
       
  1820 			else if(TSpdiaIndexDataVPbk::OPERATION_ASSIGN_CONTACT == operation)
       
  1821 			{
       
  1822           iSpeedDial->SetIndex(index + 1);
       
  1823           TRAP_IGNORE(
       
  1824               {
       
  1825               MVPbkStoreContactFieldCollection* fieldCollection = iAttributeManager->FindFieldsWithAttributeLC( *( iSpeedDial ), *aContact ); 
       
  1826               if ( fieldCollection && ( fieldCollection->FieldCount() > 0 ) )
       
  1827                   {
       
  1828                   // update speeddial information
       
  1829                   MVPbkStoreContactField& field = fieldCollection->FieldAt( 0 );
       
  1830                   ( *iSdmArray )[ index ].SetContactLink( field.CreateLinkLC() );
       
  1831                   ( *iSdmArray )[ index ].SetContact( aContact );
       
  1832                   CleanupStack::Pop();
       
  1833                   SetDetails( index );
       
  1834                   }
       
  1835 
       
  1836           		CleanupStack::PopAndDestroy(); // Pop and Destroy FieldCollection
       
  1837               }
       
  1838           )				
       
  1839 				  iRetrieveComplete = ETrue;
       
  1840 				  Release();
       
  1841 			}
       
  1842 		 	//delete &aOperation;
       
  1843 		}
       
  1844  	}
       
  1845 }
       
  1846 
       
  1847 // ---------------------------------------------------------
       
  1848 // CSpeedDialPrivate::VPbkSingleContactOperationFailed()
       
  1849 //
       
  1850 // ---------------------------------------------------------
       
  1851 void CSpeedDialPrivate::VPbkSingleContactOperationFailed(
       
  1852                  MVPbkContactOperationBase& /*aOperation*/, 
       
  1853                  TInt aError)
       
  1854 {
       
  1855 	iError = aError;
       
  1856 	iRetrieveComplete = ETrue;
       
  1857 	Release();
       
  1858 
       
  1859 }
       
  1860                  
       
  1861 // ---------------------------------------------------------
       
  1862 // CSpeedDialPrivate::ShowAssignL()
       
  1863 //
       
  1864 // ---------------------------------------------------------
       
  1865 TBool CSpeedDialPrivate::ShowAssignL( MVPbkContactLink& aContactLink, TInt& aIndex )
       
  1866 {
       
  1867 	TBool aReturn (EFalse);
       
  1868 	
       
  1869     TRAPD(err,iGridDlg = CSpdiaGridDlgVPbk::NewL(aIndex, *this));
       
  1870     
       
  1871     // Execute the CPbkFetchEntryDlg dialog
       
  1872     TInt result(ETrue);
       
  1873     
       
  1874 	if(err == KErrNone)
       
  1875 	{
       
  1876 	    TRAPD(error, result = iGridDlg->ExecuteLD(R_SPDIA_GRID_DIALOG));
       
  1877     	iGridDlg = NULL; 
       
  1878     	iIconArray = NULL;	
       
  1879     	 // Check errors
       
  1880     	User::LeaveIfError(error);
       
  1881 	}
       
  1882 
       
  1883   
       
  1884    
       
  1885    	TBool popUp = ETrue;
       
  1886    	
       
  1887     if (iBooleanVarForAddingDialogVariation)
       
  1888 	{
       
  1889 		if(!CheckingIfPopUpNeededL())
       
  1890 		  popUp = EFalse;
       
  1891 	}
       
  1892    	if (popUp && result && !CheckSpaceBelowCriticalLevelL())
       
  1893    	{
       
  1894 	//for contact link
       
  1895   	TUint assignFlags = 0; 
       
  1896     ExecuteSingleEntryAssignL(aIndex-1,AiwContactAssign:: TAiwContactAttributeAssignDataV1().SetFlags(assignFlags));//amit
       
  1897     aReturn = ETrue;
       
  1898     //return aReturn;
       
  1899     // for contact link
       
  1900 		   	    	    
       
  1901 		if((*iSdmArray)[aIndex-1].Contact() != NULL)
       
  1902 		{
       
  1903 			result = RemoveSpeedDialL(aIndex-1);
       
  1904 		}
       
  1905 		
       
  1906 		//If removal was successful
       
  1907 		if(result != EFalse)
       
  1908 		{
       
  1909 		   	iRetrieveComplete = EFalse;
       
  1910 		   	if(iContactLink)
       
  1911 		   	{
       
  1912 		   		delete iContactLink;
       
  1913 		   		iContactLink= NULL;
       
  1914 		   	}
       
  1915 		 	iContactLink = aContactLink.CloneLC();
       
  1916 		 	CleanupStack::Pop();
       
  1917 		 	
       
  1918 	    MVPbkContactOperationBase* operation = iContactManager->RetrieveContactL( aContactLink, (*this ));
       
  1919 		   		      
       
  1920 		    if(operation)
       
  1921 		    {
       
  1922 				(*iSdmArray)[aIndex-1].SetOperation(operation,TSpdiaIndexDataVPbk::OPERATION_ASSIGN);
       
  1923 				
       
  1924 				while (!iRetrieveComplete)
       
  1925 			    {
       
  1926 			    	Wait();
       
  1927 			    }
       
  1928 			    //If retrieval is successful
       
  1929 				if(iError == KErrNone)
       
  1930 				{
       
  1931 					AssignSpeedDialL(aIndex-1);				
       
  1932 					aReturn = ETrue;
       
  1933 				}
       
  1934 				else
       
  1935 				{
       
  1936 					delete iContactLink;
       
  1937 				}
       
  1938 			   	
       
  1939 		    }
       
  1940 		}
       
  1941 	    
       
  1942 	    iContactLink = NULL;
       
  1943    	}
       
  1944 
       
  1945 	return aReturn;	   	
       
  1946 }
       
  1947 
       
  1948 // ---------------------------------------------------------
       
  1949 // CSpeedDialPrivate::ShowAssignL()
       
  1950 //
       
  1951 // ---------------------------------------------------------
       
  1952 TBool CSpeedDialPrivate::ShowAssignL( TInt aIndex, MVPbkContactLink*& aContactLink  )
       
  1953     {
       
  1954 
       
  1955     // Have to display the title of SpeedDial when called 
       
  1956     // from SpeedDial application...May be that function can be moved to
       
  1957     // speed dial application...
       
  1958 
       
  1959     TBool result = ETrue;
       
  1960     HBufC* prompt = NULL;
       
  1961     TBuf<KOperatorNameLength> operatorName;
       
  1962     
       
  1963     aIndex = aIndex-1;
       
  1964     if (iBooleanVarForAddingDialogVariation )
       
  1965         {
       
  1966         if(iPopupDialog)
       
  1967             {
       
  1968             if(!CheckingIfPopUpNeededL())
       
  1969             result = EFalse;
       
  1970             }
       
  1971         }
       
  1972 
       
  1973     if ( !CheckSpaceBelowCriticalLevelL() )
       
  1974         {
       
  1975         if ( result && (*iSdmArray)[aIndex].Contact() != NULL )
       
  1976             {
       
  1977             //if(iGridUsed == EGridNoUse)//because grid will be used if you want to replace or change
       
  1978             if ( iGridUsed == EGridUse )
       
  1979                 {
       
  1980                 MakeVisible( ETrue );
       
  1981                 result = ETrue;
       
  1982                 MakeVisible( EFalse );
       
  1983                 }
       
  1984             }
       
  1985 
       
  1986         if(result)
       
  1987             {
       
  1988             TUint assignFlags = 0;            
       
  1989             //assignFlags |= (AiwContactAssign::EUseProviderTitle);//|AiwContactAssign::EDoNotOpenEditor); 
       
  1990             CAknTitlePane* title = NULL;
       
  1991             CEikStatusPane *sp = CEikonEnv::Static()->AppUiFactory()->StatusPane();
       
  1992             title =  STATIC_CAST(CAknTitlePane*, sp->ControlL( TUid::Uid(EEikStatusPaneUidTitle) ) );
       
  1993             prompt = StringLoader::LoadLC(R_QTN_SPDIA_TITLE, iCoeEnv);
       
  1994             operatorName.Copy(*title->Text());
       
  1995             title->SetTextL(*prompt);
       
  1996             title->MakeVisible(ETrue);
       
  1997             CleanupStack::PopAndDestroy(prompt); 
       
  1998             
       
  1999             ExecuteSingleEntryAssignL(aIndex,AiwContactAssign:: TAiwContactAttributeAssignDataV1().SetFlags(assignFlags));
       
  2000 
       
  2001             if ( iCancelFlag )
       
  2002                 {
       
  2003                 iCancelFlag = EFalse;
       
  2004                 return result;
       
  2005                 }
       
  2006 
       
  2007             if ( iError == KErrNone && iContactLink != NULL )
       
  2008                 {
       
  2009                 (*iSdmArray)[aIndex].Reset();
       
  2010                 //Retrieve Contact and assign fields to the index..
       
  2011                 iRetrieveComplete = EFalse;
       
  2012                 MVPbkContactOperationBase* operation = iContactManager->RetrieveContactL( *iContactLink, (*this ));
       
  2013 
       
  2014                 if(operation)
       
  2015                     {
       
  2016                     (*iSdmArray)[aIndex].SetOperation(operation,TSpdiaIndexDataVPbk::OPERATION_ASSIGN_CONTACT);
       
  2017 
       
  2018                     while (!iRetrieveComplete)
       
  2019                         {
       
  2020                         Wait();
       
  2021                         }
       
  2022                     if ( iError == KErrNone )
       
  2023                         {
       
  2024                         result = ETrue;	
       
  2025                         }
       
  2026                     else
       
  2027                         {
       
  2028                         //We are taking a copy of contact links..
       
  2029                         //If we can't store it, delete the link..
       
  2030                         delete iContactLink;
       
  2031                         iContactLink = NULL;
       
  2032                         result = EFalse;
       
  2033                         }
       
  2034                     }
       
  2035                 }
       
  2036 
       
  2037             else if( iError == KErrInUse )
       
  2038                 {
       
  2039                 ShowNoteL( R_QTN_SPDIA_CONTACT_IN_USE );
       
  2040                 }
       
  2041 
       
  2042             if(iContactLink != NULL)
       
  2043                 {
       
  2044                 aContactLink = iContactLink->CloneLC();
       
  2045                 CleanupStack::Pop();	    		
       
  2046                 delete iContactLink;
       
  2047                 }
       
  2048             else
       
  2049                 {
       
  2050                 aContactLink = CONST_CAST(MVPbkContactLink*, iContactLink);
       
  2051                 }
       
  2052             iContactLink = NULL;
       
  2053 
       
  2054             title->SetTextL( operatorName );
       
  2055             } 
       
  2056         }
       
  2057 
       
  2058         return result;
       
  2059 
       
  2060     }
       
  2061 
       
  2062 // ---------------------------------------------------------
       
  2063 // CSpeedDialPrivate::ShowRemoveL
       
  2064 //
       
  2065 // ---------------------------------------------------------
       
  2066 //
       
  2067 TBool CSpeedDialPrivate::ShowRemoveL( TInt aIndex )
       
  2068 {
       
  2069 
       
  2070 	TBool aReturn = EFalse;
       
  2071 		
       
  2072     if ( (!CheckSpaceBelowCriticalLevelL() )&&( (*iSdmArray)[aIndex].Contact()!= NULL ))
       
  2073 	{
       
  2074 		iState = STATE_REMOVE;
       
  2075 		if((*iSdmArray)[aIndex].Field() != NULL)
       
  2076 		{
       
  2077 			iOperationComplete = EFalse;
       
  2078 			iSpeedDial->SetIndex(aIndex+1);
       
  2079 			(*iSdmArray)[aIndex].Contact()->LockL(*(this));
       
  2080 
       
  2081 			while(!iOperationComplete)
       
  2082 			{
       
  2083 				Wait();
       
  2084 			}
       
  2085 
       
  2086 			if(iError == KErrNone)
       
  2087 			{
       
  2088 				
       
  2089 				MVPbkStoreContactField* field = (*iSdmArray)[aIndex].Field();
       
  2090 				TPtrC label = field->FieldLabel();
       
  2091 				iOperationComplete = EFalse;
       
  2092 				MVPbkContactOperationBase* operation = NULL; 
       
  2093 				operation = iAttributeManager->RemoveFieldAttributeL(
       
  2094 														*field, *iSpeedDial, (*this));
       
  2095 				if(operation)
       
  2096 				{
       
  2097 					(*iSdmArray)[aIndex].SetOperation(operation,TSpdiaIndexDataVPbk::OPERATION_REMOVE);
       
  2098 				
       
  2099 					while(!iOperationComplete)
       
  2100 					{
       
  2101 						Wait();
       
  2102 					}
       
  2103 
       
  2104 				}
       
  2105 				
       
  2106 				//If there are no errors
       
  2107 				if(iError == KErrNone)
       
  2108 				{
       
  2109 					aReturn = ETrue;
       
  2110 				}
       
  2111 			}
       
  2112             else if( iError == KErrInUse )
       
  2113                 {
       
  2114                 // Prompt information note when contact is in use
       
  2115                 ShowNoteL( R_QTN_SPDIA_CONTACT_IN_USE );
       
  2116                 }
       
  2117 		}
       
  2118 	}
       
  2119 	
       
  2120 	return aReturn;
       
  2121 }
       
  2122 
       
  2123 // ---------------------------------------------------------
       
  2124 // CSpeedDialPrivate::ShowAssign
       
  2125 // Function called when assigning speed dial from phone book
       
  2126 // application
       
  2127 // ---------------------------------------------------------
       
  2128 //
       
  2129 EXPORT_C TInt CSpeedDialPrivate::ShowAssign( MVPbkContactLink& aContactLink, TInt& aIndex )
       
  2130    	{
       
  2131    	iError = KErrNone;
       
  2132    	iCurrentIndex = aIndex - 1;
       
  2133 
       
  2134    	TRAPD( err, ShowAssignL( aContactLink, aIndex ) );
       
  2135 
       
  2136    	if ( err )
       
  2137    	   	{
       
  2138    	   	iError = err;
       
  2139    	   	}
       
  2140 
       
  2141    	iCurrentIndex = -1;
       
  2142    	return iError;	
       
  2143    	}
       
  2144 	
       
  2145 // ---------------------------------------------------------
       
  2146 // CSpdiaContainer::ShowAssignL
       
  2147 // Function called when assigning speed dial from SpeedDial and Telephony
       
  2148 // application
       
  2149 // ---------------------------------------------------------
       
  2150 //
       
  2151 	
       
  2152 EXPORT_C TInt CSpeedDialPrivate::ShowAssign( TInt aIndex, MVPbkContactLink*& aContactLink  )
       
  2153    	{
       
  2154    	iError = KErrNone;
       
  2155    	if ( !iShowAssignCalled )
       
  2156    	   	{
       
  2157    	   	iShowAssignCalled = ETrue;
       
  2158    	   	iCurrentIndex = aIndex - 1;
       
  2159 
       
  2160    	   	TRAPD( err, ShowAssignL( aIndex, aContactLink ) );
       
  2161 
       
  2162    	   	if ( err )
       
  2163    	   	   	{
       
  2164    	   	   	iError = err;
       
  2165    	   	   	}
       
  2166    	   	iCurrentIndex = -1;
       
  2167    	   	iShowAssignCalled = EFalse;
       
  2168    	   	} 	
       
  2169 
       
  2170    	return iError;
       
  2171    	}
       
  2172 
       
  2173 EXPORT_C TInt CSpeedDialPrivate::ShowRemove( TInt aIndex )
       
  2174    	{
       
  2175    	iError = KErrNone;
       
  2176 
       
  2177    	iCurrentIndex = aIndex;
       
  2178    	TInt reValue = ETrue;
       
  2179    	TRAP_IGNORE( reValue = ShowRemoveL( aIndex ) );
       
  2180 
       
  2181    	iCurrentIndex = -1;
       
  2182    	return reValue;
       
  2183    	}
       
  2184 
       
  2185     
       
  2186 // --------------------------------------------------------------------------
       
  2187 // CSpeedDialPrivate::StoreReady
       
  2188 //
       
  2189 // --------------------------------------------------------------------------
       
  2190 //
       
  2191 void CSpeedDialPrivate::StoreReady(MVPbkContactStore& /*aContactStore*/)
       
  2192     {
       
  2193     	iOperationComplete = ETrue;
       
  2194     	Release();
       
  2195     }
       
  2196     
       
  2197 // --------------------------------------------------------------------------
       
  2198 // CSpeedDialPrivate::StoreUnavailable
       
  2199 //
       
  2200 // --------------------------------------------------------------------------
       
  2201 //
       
  2202 void CSpeedDialPrivate::StoreUnavailable
       
  2203         (MVPbkContactStore& /*aContactStore*/, TInt /*aReason*/)
       
  2204     {
       
  2205     	iOperationComplete = ETrue;
       
  2206     	Release();
       
  2207 
       
  2208     	//iError = aReason;
       
  2209     }
       
  2210 
       
  2211 // --------------------------------------------------------------------------
       
  2212 // CSpeedDialPrivate::SetState
       
  2213 //
       
  2214 // --------------------------------------------------------------------------
       
  2215 //    
       
  2216 EXPORT_C void CSpeedDialPrivate::SetState(eSpeedDialState aState)
       
  2217 {
       
  2218 	iState = aState;
       
  2219 }
       
  2220 
       
  2221 // --------------------------------------------------------------------------
       
  2222 // CSpeedDialPrivate::State
       
  2223 //
       
  2224 // --------------------------------------------------------------------------
       
  2225 // 
       
  2226 EXPORT_C  CSpeedDialPrivate::eSpeedDialState CSpeedDialPrivate::State()
       
  2227 {
       
  2228 	return iState;
       
  2229 }
       
  2230 
       
  2231 // --------------------------------------------------------------------------
       
  2232 // CSpeedDialPrivate::GridStatus
       
  2233 //
       
  2234 // --------------------------------------------------------------------------
       
  2235 // 
       
  2236 EXPORT_C  CSpeedDialPrivate::TGridUse CSpeedDialPrivate::GridStatus()
       
  2237 {
       
  2238 	return iGridUsed;
       
  2239 }
       
  2240 
       
  2241 // --------------------------------------------------------------------------
       
  2242 // CSpeedDialPrivate::SetGridStatus
       
  2243 //
       
  2244 // --------------------------------------------------------------------------
       
  2245 // 
       
  2246 EXPORT_C  void CSpeedDialPrivate::SetGridStatus(TGridUse aStatus)
       
  2247 {
       
  2248 	iGridUsed = aStatus;
       
  2249 }
       
  2250 
       
  2251 // --------------------------------------------------------------------------
       
  2252 // CSpeedDialPrivate::HandleStoreEventL
       
  2253 //
       
  2254 // --------------------------------------------------------------------------
       
  2255 //
       
  2256 void CSpeedDialPrivate::HandleStoreEventL(
       
  2257         MVPbkContactStore& aContactStore,
       
  2258         TVPbkContactStoreEvent aStoreEvent)
       
  2259 	{
       
  2260 	
       
  2261 	MVPbkContactStore* storeInList = iContactManager->ContactStoresL().Find(aContactStore.StoreProperties().Uri());
       
  2262 	
       
  2263 	if (storeInList !=NULL)
       
  2264 	{
       
  2265 	switch(aStoreEvent.iEventType)
       
  2266 		{
       
  2267 		
       
  2268 		case TVPbkContactStoreEvent::EContactChanged:
       
  2269 		case TVPbkContactStoreEvent::EContactDeleted:
       
  2270 		
       
  2271 		if ( iState == STATE_IDLE /*&& iUpdateFlag == EFalse*/ )
       
  2272 			{
       
  2273 			
       
  2274 			TInt findResult = 0;
       
  2275 			findResult = FindInSpeedDialContacts(aStoreEvent.iContactLink);
       
  2276 			
       
  2277 			if(findResult != EFalse)
       
  2278 				{
       
  2279 				if (iGridUsed != EGridUse)
       
  2280 					{
       
  2281 					if ( iRemoveConfirmQueryDialog 
       
  2282 						&& aStoreEvent.iEventType == TVPbkContactStoreEvent:: EContactChanged
       
  2283 						&& iCurrentIndex == findResult )
       
  2284 						{
       
  2285 						delete iRemoveConfirmQueryDialog;
       
  2286 						iRemoveConfirmQueryDialog = NULL;
       
  2287 						}
       
  2288 					iUpdateFlag = ETrue;
       
  2289 					// if CSpeedDialPrivate object is constructed by dialer, the value of iGrid is NULL
       
  2290 					if ( iGrid )
       
  2291 						{
       
  2292 						CreateDataL( *iGrid  );
       
  2293 						}
       
  2294 					// If the view number note popped up and the customer delete the image of contact
       
  2295 					// Set the update flag.
       
  2296 					if ( iRefreshObserver && iCurrentIndex == findResult )
       
  2297 						{
       
  2298 						iUpdateFlag = ETrue;
       
  2299 						}
       
  2300 					}
       
  2301 				}
       
  2302 			else
       
  2303 				{
       
  2304 				if(CheckContactAssignedFromPhoneBookL(aStoreEvent.iContactLink))
       
  2305 					{
       
  2306 					if (iGridUsed != EGridUse)
       
  2307 						{
       
  2308 						iUpdateFlag = ETrue;
       
  2309 						// if CSpeedDialPrivate object is constructed by dialer, the value of iGrid is NULL
       
  2310 						if ( iGrid )
       
  2311 							{
       
  2312 							CreateDataL( *iGrid  );
       
  2313 							}
       
  2314 						}
       
  2315 					}
       
  2316 				
       
  2317 				}
       
  2318 			}	
       
  2319 		break;
       
  2320 		
       
  2321 		default:
       
  2322 		break;
       
  2323 		}
       
  2324 	
       
  2325 	}
       
  2326 	
       
  2327 	}
       
  2328 
       
  2329 // --------------------------------------------------------------------------
       
  2330 // CSpeedDialPrivate::SetUpdateFlag
       
  2331 //
       
  2332 // --------------------------------------------------------------------------
       
  2333 //
       
  2334 EXPORT_C void CSpeedDialPrivate::SetUpdateFlag(TBool aFlag)
       
  2335 {
       
  2336 	iUpdateFlag = aFlag;
       
  2337 }
       
  2338 
       
  2339 // --------------------------------------------------------------------------
       
  2340 // CSpeedDialPrivate::UpdateFlag
       
  2341 //
       
  2342 // --------------------------------------------------------------------------
       
  2343 //
       
  2344 
       
  2345 EXPORT_C TBool CSpeedDialPrivate::UpdateFlag()
       
  2346 {
       
  2347 	return iUpdateFlag;
       
  2348 }
       
  2349 
       
  2350 // --------------------------------------------------------------------------
       
  2351 // CSpeedDialPrivate::FindInSpeedDialContacts
       
  2352 //
       
  2353 // --------------------------------------------------------------------------
       
  2354 //
       
  2355     
       
  2356 TInt CSpeedDialPrivate::FindInSpeedDialContacts(MVPbkContactLink* aContactLink)    
       
  2357     {
       
  2358     // TBool found = EFalse;
       
  2359     TInt found = 0;
       
  2360     MVPbkStoreContact* contact = NULL;
       
  2361     for ( TInt count = 0; count < iSdmArray->Count() && found != iCurrentIndex; ++count )
       
  2362         {
       
  2363         contact = ( *iSdmArray )[count].Contact();
       
  2364         
       
  2365         if ( contact != NULL && aContactLink->RefersTo( *contact ) )
       
  2366             {
       
  2367             found = iSdmArray->Count();
       
  2368             // if the changed contact is the one which is focused in Speeddial,
       
  2369             // then the note can be removed
       
  2370             if ( count == iCurrentIndex )
       
  2371                 {
       
  2372                 found = iCurrentIndex;
       
  2373                 }
       
  2374             }
       
  2375         }
       
  2376     return found;
       
  2377     }
       
  2378 
       
  2379 // --------------------------------------------------------------------------
       
  2380 // CSpeedDialPrivate::CheckContactAssignedFromPhoneBookL
       
  2381 //
       
  2382 // --------------------------------------------------------------------------
       
  2383 //
       
  2384 TBool CSpeedDialPrivate::CheckContactAssignedFromPhoneBookL(MVPbkContactLink* aContactLink)
       
  2385 {
       
  2386 	TBool aReturn = EFalse;
       
  2387 	iRetrieveComplete = EFalse;
       
  2388 	MVPbkContactOperationBase* operation = iContactManager->RetrieveContactL( *aContactLink,
       
  2389 											(*this ));
       
  2390 	//Save the old state																
       
  2391 	eSpeedDialState oldState = iState;
       
  2392 	
       
  2393 	iState = STATE_CONTACTCHANGE;
       
  2394 	if(operation != NULL)
       
  2395 	{
       
  2396 		while(!iRetrieveComplete)
       
  2397 		{
       
  2398 			Wait();
       
  2399 		}
       
  2400 		
       
  2401 		delete operation;
       
  2402 		if(iContact != NULL)
       
  2403 		{
       
  2404 			aReturn = iAttributeManager->HasContactAttributeL(
       
  2405 										CVPbkSpeedDialAttribute::Uid(),*iContact);
       
  2406 			delete iContact;
       
  2407 			iContact = NULL;
       
  2408 		}	
       
  2409 	}
       
  2410 
       
  2411 	//Restore the old state
       
  2412 	iState  = oldState;
       
  2413 	return aReturn;
       
  2414 	
       
  2415 }
       
  2416 
       
  2417 
       
  2418 // --------------------------------------------------------------------------
       
  2419 // CSpeedDialPrivate::ExecuteSingleEntryAssignL
       
  2420 //
       
  2421 // --------------------------------------------------------------------------
       
  2422 //
       
  2423 void CSpeedDialPrivate::ExecuteSingleEntryAssignL(TInt aIndex,
       
  2424         AiwContactAssign::TAiwContactAttributeAssignDataV1 aData)
       
  2425     { 
       
  2426     iState = STATE_ASSIGN;
       
  2427         
       
  2428     CAiwGenericParamList& inParamList = iServiceHandler->InParamListL(); 
       
  2429     
       
  2430     const TAiwVariant speedDialVariant( aIndex + 1 );
       
  2431     /*
       
  2432     TGenericParamId genericParam =
       
  2433         TGenericParamId( EGenericParamSpeedDialIndex );*/
       
  2434 	//For the time being..phone book ui lib is compiled with this value...     
       
  2435     TGenericParamId genericParam =
       
  2436         TGenericParamId( EGenericParamSpeedDialIndex );
       
  2437   
       
  2438     inParamList.AppendL(TAiwGenericParam(
       
  2439                     genericParam,
       
  2440                     speedDialVariant
       
  2441                     ) );  
       
  2442   
       
  2443     inParamList.AppendL( TAiwGenericParam( EGenericParamContactAssignData,
       
  2444             TAiwVariant( AiwContactAssign::TAiwContactAttributeAssignDataV1Pckg( aData ) ) ) );
       
  2445                                      
       
  2446 
       
  2447 	iOperationComplete = EFalse;
       
  2448 	iContactLink = NULL;
       
  2449     iServiceHandler->ExecuteServiceCmdL(
       
  2450             KAiwCmdAssign, 
       
  2451             inParamList, 
       
  2452             iServiceHandler->OutParamListL(),
       
  2453             0,
       
  2454             this );                
       
  2455     
       
  2456     // Wait till the contact is selected
       
  2457     while ( !iOperationComplete )
       
  2458         {
       
  2459         Wait();
       
  2460         }
       
  2461     
       
  2462     // CleanupStack::PopAndDestroy();
       
  2463     //iServiceHandler = NULL;
       
  2464     }
       
  2465 
       
  2466 // --------------------------------------------------------------------------
       
  2467 // CSpeedDialPrivate::ExecuteSingleEntryFetchL
       
  2468 //
       
  2469 // --------------------------------------------------------------------------
       
  2470 //
       
  2471 void CSpeedDialPrivate::ExecuteSingleEntryFetchL(TInt aIndex,
       
  2472         TAiwSingleEntrySelectionDataV2 aData,
       
  2473         const TDesC& aUri1)
       
  2474 { 
       
  2475     CAiwServiceHandler* serviceHandler = CAiwServiceHandler::NewL();
       
  2476     
       
  2477     serviceHandler->AttachL(R_SPDIA_SINGLE_ENTRY_FETCH_INTEREST);
       
  2478     
       
  2479     CleanupStack::PushL(serviceHandler);  
       
  2480         
       
  2481     CAiwGenericParamList& inParamList = serviceHandler->InParamListL();    
       
  2482     inParamList.AppendL(
       
  2483         TAiwGenericParam(
       
  2484             EGenericParamContactSelectionData,
       
  2485             TAiwVariant(TAiwSingleEntrySelectionDataV2Pckg(aData))));
       
  2486 
       
  2487     CVPbkContactStoreUriArray* uriArray = CVPbkContactStoreUriArray::NewL();
       
  2488     CleanupStack::PushL(uriArray);
       
  2489     if (aUri1.Length() > 0) 
       
  2490 	    {
       
  2491 	    uriArray->AppendL(aUri1);
       
  2492 			}  
       
  2493 
       
  2494     HBufC8* packedUris = uriArray->PackLC();
       
  2495     if (uriArray->Count() > 0)
       
  2496         {
       
  2497         inParamList.AppendL(
       
  2498         TAiwGenericParam(
       
  2499                 EGenericParamContactStoreUriArray,
       
  2500                 TAiwVariant(*packedUris)));
       
  2501         }
       
  2502 
       
  2503 	iOperationComplete = EFalse;
       
  2504 	iContactLink = NULL;
       
  2505     serviceHandler->ExecuteServiceCmdL(
       
  2506             KAiwCmdSelect, 
       
  2507             inParamList, 
       
  2508             serviceHandler->OutParamListL(),
       
  2509             0,
       
  2510             this);                
       
  2511     CleanupStack::PopAndDestroy(2); // packedUris, uriArray, service handler
       
  2512     
       
  2513     //Wait till the contact is selected
       
  2514     while (!iOperationComplete)
       
  2515     {
       
  2516     	Wait();
       
  2517     }
       
  2518     
       
  2519     CleanupStack::PopAndDestroy(serviceHandler);
       
  2520     
       
  2521     if(iContactLink && !CheckSpaceBelowCriticalLevelL())
       
  2522     {
       
  2523     	iRetrieveComplete = EFalse;
       
  2524     	
       
  2525     	MVPbkContactOperationBase* operation = iContactManager->RetrieveContactL( *iContactLink, (*this ));
       
  2526 	      
       
  2527 	    if(operation)
       
  2528 	    {
       
  2529 			(*iSdmArray)[aIndex].SetOperation(operation,TSpdiaIndexDataVPbk::OPERATION_ASSIGN);
       
  2530 			
       
  2531 			while (!iRetrieveComplete)
       
  2532 		    {
       
  2533 		    	Wait();
       
  2534 		    }
       
  2535 		    
       
  2536 		    ShowRemove(aIndex);
       
  2537 			if(iError == 0)
       
  2538 			{
       
  2539 				
       
  2540 			}   	
       
  2541 	    }
       
  2542 	    
       
  2543     }
       
  2544 }
       
  2545 
       
  2546 // --------------------------------------------------------------------------
       
  2547 // CSpeedDialPrivate::HandleNotifyL
       
  2548 //
       
  2549 // --------------------------------------------------------------------------
       
  2550 //
       
  2551 TInt CSpeedDialPrivate::HandleNotifyL(
       
  2552         TInt aCmdId,
       
  2553         TInt aEventId,
       
  2554         CAiwGenericParamList& aEventParamList,
       
  2555         const CAiwGenericParamList& /*aInParamList*/)
       
  2556 {
       
  2557     TInt result = 0;
       
  2558     iContactLink = NULL;
       
  2559     
       
  2560       if ((aCmdId == KAiwCmdSelect) || (aCmdId == KAiwCmdAssign))
       
  2561         {
       
  2562         if (aEventId == KAiwEventCompleted)
       
  2563             {
       
  2564             TInt index = 0;
       
  2565             const TAiwGenericParam* param =
       
  2566                 aEventParamList.FindFirst(index, EGenericParamContactLinkArray);
       
  2567             if ( !iFetchmail && param)
       
  2568                 {
       
  2569                 TPtrC8 contactLinks = param->Value().AsData();
       
  2570                 CVPbkContactLinkArray* links = CVPbkContactLinkArray::NewLC(
       
  2571                         contactLinks,iContactManager->ContactStoresL());
       
  2572 	            
       
  2573 	            if(links->Count() > 0)
       
  2574 	           	{
       
  2575 	           	    if(iContactLink)
       
  2576 		         	{
       
  2577 		   	        	delete iContactLink;
       
  2578 		   		        iContactLink= NULL;
       
  2579 		   	         }
       
  2580 		  
       
  2581 	           		iContactLink = links->At(0).CloneLC();
       
  2582 	           		CleanupStack::Pop();
       
  2583 	           	}
       
  2584 	           	
       
  2585                 CleanupStack::PopAndDestroy(links);
       
  2586                 }
       
  2587                 
       
  2588             index = 1;
       
  2589             const TAiwGenericParam* paramMail =
       
  2590                 aEventParamList.FindFirst(index, EGenericParamContactFieldData);   
       
  2591             if ( iFetchmail && paramMail )
       
  2592             	{  
       
  2593                 TInt length = paramMail->Value().AsDes().Length();
       
  2594                 iMail = HBufC::NewL(length);
       
  2595                 iMail->Des().Append(paramMail->Value().AsDes());
       
  2596             	}            
       
  2597 
       
  2598             if( iFetchmail )
       
  2599                 {
       
  2600                 iFetchmailComplete = ETrue;
       
  2601                 ReleaseFetchMail();
       
  2602                 }
       
  2603             else
       
  2604                 {
       
  2605                 iOperationComplete = ETrue;
       
  2606                 Release();
       
  2607                 }  
       
  2608 
       
  2609             }
       
  2610         else if (aEventId == KAiwEventCanceled)
       
  2611             {
       
  2612             	iError = KErrCancel;    
       
  2613 
       
  2614                 if( iFetchmail )
       
  2615                     {
       
  2616                     iFetchmailComplete = ETrue;
       
  2617                     ReleaseFetchMail();
       
  2618                     }
       
  2619                 else
       
  2620                     {
       
  2621                     iOperationComplete = ETrue;
       
  2622                     Release();
       
  2623 	                }
       
  2624             }
       
  2625          else if (aEventId == KAiwEventError)
       
  2626          	{
       
  2627          	   	iError = KErrInUse;    
       
  2628 	           	iOperationComplete = ETrue;
       
  2629 	    		Release();
       
  2630          	}
       
  2631          else if(aEventId == KAiwEventQueryExit)	
       
  2632          	{
       
  2633                 iError = KLeaveExit;    
       
  2634 	            iOperationComplete = ETrue;
       
  2635 	    		Release();
       
  2636                 result = 1;
       
  2637            	}
       
  2638        }
       
  2639 
       
  2640     return result;
       
  2641  }
       
  2642 
       
  2643 // --------------------------------------------------------------------------
       
  2644 // CSpeedDialPrivate::ContactOperationCompleted
       
  2645 //
       
  2646 // --------------------------------------------------------------------------
       
  2647 //
       
  2648 void CSpeedDialPrivate::ContactOperationCompleted(TContactOpResult /*aResult*/)
       
  2649 {
       
  2650 	iOperationComplete = ETrue;
       
  2651 	Release();
       
  2652 
       
  2653 }
       
  2654 
       
  2655 // --------------------------------------------------------------------------
       
  2656 // CSpeedDialPrivate::ContactOperationFailed
       
  2657 //
       
  2658 // --------------------------------------------------------------------------
       
  2659 //
       
  2660 void CSpeedDialPrivate::ContactOperationFailed(TContactOp /*aOpCode*/, TInt aErrorCode, 
       
  2661         							TBool /*aErrorNotified*/)
       
  2662 {
       
  2663 	iError = aErrorCode;
       
  2664 	iOperationComplete = ETrue;
       
  2665 	Release();
       
  2666 }
       
  2667 
       
  2668 // ---------------------------------------------------------
       
  2669 // CSpeedDialPrivate::InitIndexDataL
       
  2670 // The SDM control data is initialized.
       
  2671 // ---------------------------------------------------------
       
  2672 //
       
  2673 void CSpeedDialPrivate::InitIndexDataL()
       
  2674 {
       
  2675     // The dialog of grid is not closed.
       
  2676     if (iIconArray != NULL)
       
  2677     {
       
  2678         iError = KErrNone;
       
  2679         ResetArray();
       
  2680         //State set to identify the source of call during callback.
       
  2681         
       
  2682         //Save the old state
       
  2683         eSpeedDialState oldState = iState;
       
  2684         
       
  2685         iState = STATE_INITIAL;
       
  2686         iOperationComplete = EFalse;
       
  2687 
       
  2688 		/*Delete already fetched contacts if any */
       
  2689 		if(iContactLinkArray != NULL)
       
  2690 		{
       
  2691 			delete iContactLinkArray;
       
  2692 			iContactLinkArray = NULL;
       
  2693 		}
       
  2694         //Fetch all contacts for which speed dial attribute is set.
       
  2695         iFetchAll = EFalse;
       
  2696         iSpeedDial->SetIndex(CVPbkSpeedDialAttribute::KSpeedDialIndexNotDefined);
       
  2697        // iSpeedDial->SetIndex(2);
       
  2698        	MVPbkContactOperationBase* findOperation = iAttributeManager->ListContactsL(*iSpeedDial,(*this));
       
  2699        
       
  2700         while(findOperation != NULL && !iFetchAll)
       
  2701         {
       
  2702         	//Wait till every contactlink is fetched and set.
       
  2703         	Wait();
       
  2704         }
       
  2705         //Delete the handle
       
  2706         delete findOperation;
       
  2707         
       
  2708         MVPbkContactOperationBase* retrieveOperation = NULL;
       
  2709         for(TInt count =0; iContactLinkArray && count < iContactLinkArray->Count();++count)
       
  2710         {
       
  2711         	iRetrieveComplete = EFalse;     
       
  2712         	iContactLink = &(iContactLinkArray->At(count));
       
  2713 	 		retrieveOperation = iContactManager->RetrieveContactL(iContactLinkArray->At(count),(*this ));
       
  2714 			while(retrieveOperation != NULL && !iRetrieveComplete)
       
  2715 			{
       
  2716 				//Wait till the contact is fetched and its speed dial 
       
  2717 				//index is initialized.
       
  2718 				Wait();
       
  2719 			}
       
  2720 			//Delete the handle received
       
  2721 			delete retrieveOperation;
       
  2722 
       
  2723         }
       
  2724         // Undo this reset 
       
  2725         // Just for debugging...
       
  2726         if(iError != KErrNone)
       
  2727         {
       
  2728         	iError = KErrNone;
       
  2729         }
       
  2730 		//Reset the state 
       
  2731 		iState = oldState;
       
  2732     
       
  2733     }
       
  2734 }
       
  2735 
       
  2736 // ---------------------------------------------------------
       
  2737 // CSpeedDialPrivate::FindCompleteL
       
  2738 // .
       
  2739 // ---------------------------------------------------------
       
  2740 //
       
  2741 void CSpeedDialPrivate::FindCompleteL(MVPbkContactLinkArray* aResults)
       
  2742 {
       
  2743 	
       
  2744 	iContactLinkArray = aResults;
       
  2745 	iFetchAll = ETrue;
       
  2746 	Release();
       
  2747 	
       
  2748 	
       
  2749 }
       
  2750 
       
  2751 // ---------------------------------------------------------
       
  2752 // CSpeedDialPrivate::FindFailed
       
  2753 // 
       
  2754 // ---------------------------------------------------------
       
  2755 //
       
  2756 void CSpeedDialPrivate::FindFailed(TInt aError)
       
  2757 {
       
  2758 	iError = aError;
       
  2759 	iFetchAll = ETrue;
       
  2760 	Release();
       
  2761 }
       
  2762 // ---------------------------------------------------------
       
  2763 // CSpdiaContainer::CreateItemDescriptorL
       
  2764 //
       
  2765 // ---------------------------------------------------------
       
  2766 //
       
  2767 HBufC* CSpeedDialPrivate::CreateItemDescriptorLC(const TSpdiaIndexDataVPbk& aSdmData)
       
  2768     {
       
  2769     HBufC* des = HBufC::NewLC(KApaMaxAppCaption);
       
  2770     TPtr ptr(des->Des());
       
  2771 
       
  2772     // thumb type
       
  2773     TInt type(CSpdiaGridVPbk::EText);
       
  2774     if (aSdmData.ThumbIndex() >= 0)
       
  2775         {
       
  2776         type = ConvThumbType(aSdmData.ThumbSize());
       
  2777         }
       
  2778 
       
  2779     // Text
       
  2780     if ( type == CSpdiaGridVPbk::EText )
       
  2781         {
       
  2782         // number type icon is missing
       
  2783         TBuf<KPhCltNameBufferLength> iconInfo;
       
  2784         iconInfo.Append( KDesTab );       // 1
       
  2785         if ( aSdmData.IconIndex() >= 0 )
       
  2786             {
       
  2787             iconInfo.AppendNum( aSdmData.IconIndex() );
       
  2788             }
       
  2789         AppendTextL( aSdmData, ptr ); //  2,3,4
       
  2790         ptr.Insert( 0, iconInfo );
       
  2791         }
       
  2792     else
       
  2793         {
       
  2794         // icon + text + text + text
       
  2795         ptr.Append(KDesTab2);       // 1, 2
       
  2796         ptr.Append(KDesTab2);       // 2
       
  2797         }
       
  2798 
       
  2799     // thumbnail 5-14
       
  2800     for (TInt i(CSpdiaGridVPbk::EtnCIF90); i <= CSpdiaGridVPbk::EtnCOM; ++i)
       
  2801         {
       
  2802         AppendThumbnail(aSdmData, ptr, (type == i? ETrue: EFalse));
       
  2803         }
       
  2804 
       
  2805     // number
       
  2806     ptr.Append(KDesTab);        // 15
       
  2807     // check
       
  2808     ptr.Append(KDesTab);        // 16
       
  2809 
       
  2810     return des;
       
  2811     }
       
  2812 
       
  2813 
       
  2814 // ---------------------------------------------------------
       
  2815 // CSpeedDialPrivate::CreateDataL
       
  2816 // Set grid used flag and calls CreateDataL.
       
  2817 // ---------------------------------------------------------
       
  2818 //
       
  2819 TBool CSpeedDialPrivate::CreateDataL(const CAknGrid& aGrid)
       
  2820     {
       
  2821     TGridUse  oldStatus;
       
  2822     
       
  2823     TBool result;
       
  2824     
       
  2825     oldStatus = iGridUsed;
       
  2826     
       
  2827     iGridUsed = EGridUseAndUpdate;
       
  2828 
       
  2829     result = CreateGridDataL(CONST_CAST(CAknGrid*, &aGrid), KNullIndexData);
       
  2830     
       
  2831     iGridUsed = oldStatus;
       
  2832     
       
  2833     return result;
       
  2834     }
       
  2835     
       
  2836     	
       
  2837 // ---------------------------------------------------------
       
  2838 // CSpeedDialPrivate::AppendTextL
       
  2839 // output Text1\tText2\tText3\t
       
  2840 // ---------------------------------------------------------
       
  2841 //
       
  2842 void CSpeedDialPrivate::AppendTextL(const TSpdiaIndexDataVPbk& aSdmData, TPtr& aText)
       
  2843     {
       
  2844     if ( aSdmData.Contact() == NULL )
       
  2845         {
       
  2846         aText.Append( KDesTab2 );
       
  2847         aText.Append( KDesTab2 );
       
  2848         }
       
  2849     else
       
  2850         {
       
  2851         // Test application name formatting logic is that take last name and
       
  2852         // first name and combine them using space as a separator. If either of
       
  2853         // them exists use company name. If there are still no name use "Unnamed"
       
  2854 	    
       
  2855         // Get field types from the master field type list
       
  2856         const MVPbkFieldType* lastNameType = NULL; 
       
  2857 	      const MVPbkFieldType* firstNameType = NULL;           
       
  2858 	      const MVPbkFieldType* companyNameType =
       
  2859                 iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_COMPANYNAME );
       
  2860 	    
       
  2861         TInt language = User::Language();
       
  2862 	    
       
  2863         CDesCArrayFlat* bufs = new( ELeave ) CDesCArrayFlat( 2 );
       
  2864         CleanupStack::PushL( bufs );
       
  2865 	    
       
  2866         // Non-graphical characters are replaced with space
       
  2867         const TText KReplaceChar = ' ';
       
  2868 	        
       
  2869         if ( ( language == ELangTaiwanChinese )
       
  2870             || ( language == ELangHongKongChinese )
       
  2871             || ( language == ELangPrcChinese ) )
       
  2872      		    {
       
  2873      		    lastNameType = iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_LASTNAME );
       
  2874      		    firstNameType = iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME );            
       
  2875      		    }
       
  2876         else
       
  2877             {
       
  2878             // Change the display order as first name - last name.
       
  2879             lastNameType = iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME );
       
  2880             firstNameType = iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_LASTNAME );      
       
  2881             }
       
  2882             
       
  2883         // Contact should have only one last name field
       
  2884         CVPbkBaseContactFieldTypeIterator* itr = 
       
  2885             CVPbkBaseContactFieldTypeIterator::NewLC( *lastNameType, aSdmData.Contact()->Fields() );
       
  2886         while ( itr->HasNext() )
       
  2887             {
       
  2888 	          const MVPbkBaseContactField* field = itr->Next();
       
  2889 	          // last name field is text data
       
  2890 	          const MVPbkContactFieldTextData& data = 
       
  2891 	              MVPbkContactFieldTextData::Cast( field->FieldData() );
       
  2892 	          HBufC* lastName = data.Text().AllocLC();
       
  2893 	        
       
  2894 	          TPtr lName(NULL, 0);
       
  2895 	          lName.Set( lastName->Des() );
       
  2896          	  ReplaceNonGraphicCharacters( lName, KReplaceChar );
       
  2897          	
       
  2898          	  const TInt 	len = lName.Length();
       
  2899          	  if ( 0 < len )
       
  2900                 {
       
  2901                 bufs->AppendL( lName);
       
  2902                 }
       
  2903 	        
       
  2904             CleanupStack::PopAndDestroy( lastName );
       
  2905             }
       
  2906         CleanupStack::PopAndDestroy( itr );
       
  2907 	    
       
  2908 	    // Contact should have only one first name field
       
  2909 	    itr = CVPbkBaseContactFieldTypeIterator::NewLC( *firstNameType, 
       
  2910 	        aSdmData.Contact()->Fields() );
       
  2911 	    while ( itr->HasNext() )
       
  2912 	        {
       
  2913 	        const MVPbkBaseContactField* field = itr->Next();
       
  2914 	        // last name field is text data
       
  2915 	        const MVPbkContactFieldTextData& data = 
       
  2916 	            MVPbkContactFieldTextData::Cast( field->FieldData() );
       
  2917 	        
       
  2918 	        HBufC* firstName = data.Text().AllocLC();
       
  2919 
       
  2920 	        TPtr fName(NULL, 0);
       
  2921 	        fName.Set( firstName->Des() );
       
  2922          	ReplaceNonGraphicCharacters( fName, KReplaceChar );
       
  2923          	
       
  2924          	const TInt 	len = fName.Length();
       
  2925          	if (0 < len)
       
  2926          	{
       
  2927          		bufs->AppendL( fName);
       
  2928         	}
       
  2929 	        
       
  2930 			CleanupStack::PopAndDestroy( firstName );
       
  2931 	        }
       
  2932 	    CleanupStack::PopAndDestroy( itr );
       
  2933 	    
       
  2934 	    // No last and first name try company name
       
  2935 	    if ( bufs->Count() == 0 )
       
  2936 	        {
       
  2937 	        // Contact should have only one company name field
       
  2938 	        itr = CVPbkBaseContactFieldTypeIterator::NewLC( *companyNameType, 
       
  2939 	            aSdmData.Contact()->Fields() );
       
  2940 	        while ( itr->HasNext() )
       
  2941 	            {
       
  2942 	            const MVPbkBaseContactField* field = itr->Next();
       
  2943 	            // last name field is text data
       
  2944 	            const MVPbkContactFieldTextData& data = 
       
  2945 	                MVPbkContactFieldTextData::Cast( field->FieldData() );
       
  2946 	            HBufC* companyName = data.Text().AllocLC();
       
  2947 	            bufs->AppendL( *companyName );
       
  2948 	            CleanupStack::PopAndDestroy( companyName );
       
  2949 	            }
       
  2950 	        CleanupStack::PopAndDestroy( itr );
       
  2951 	        }
       
  2952 	    
       
  2953 	  	aText.Append(KDesTab);
       
  2954 	    // If still no name use phone number
       
  2955 	    if ( bufs->Count() == 0 )
       
  2956 	        {
       
  2957             	aText.Append(aSdmData.PhoneNumber());
       
  2958             	aText.Append(KDesTab); 
       
  2959 	        }
       
  2960 	    else
       
  2961 	    {
       
  2962 		    for ( TInt i = 0; i < bufs->Count(); ++i )
       
  2963 		    {
       
  2964 		        aText.Append( (*bufs)[i] );
       
  2965 		        aText.Append(KDesTab);
       
  2966 		    }
       
  2967 	    	
       
  2968 	    }
       
  2969 	    
       
  2970 		aText.Append(KDesTab);
       
  2971 	    CleanupStack::PopAndDestroy( bufs );	
       
  2972     }
       
  2973     
       
  2974 	AknTextUtils::DisplayTextLanguageSpecificNumberConversion (aText);
       
  2975 }
       
  2976    
       
  2977 
       
  2978 // ---------------------------------------------------------
       
  2979 // CSpdiaContainer::SetOperationsL
       
  2980 //
       
  2981 // ---------------------------------------------------------
       
  2982 //
       
  2983 void CSpeedDialPrivate::SetOperationsL()
       
  2984     {
       
  2985     for (TInt index(iSdmArray->Count() -1); index > 0; --index)
       
  2986         {
       
  2987         TSpdiaIndexDataVPbk& data = (*iSdmArray)[index];
       
  2988         
       
  2989         if (data.ThumbIndex() >=0)
       
  2990             {
       
  2991             iOperationComplete = EFalse;
       
  2992             data.SetImageOperation(
       
  2993                     iImageManager->GetImageAsyncL(NULL,*(data.Contact()),*iThumbNailFieldType,(*this) ) );
       
  2994             while ( !iOperationComplete )
       
  2995                 {
       
  2996                 Wait();
       
  2997                 }
       
  2998             }
       
  2999         }
       
  3000     }
       
  3001 
       
  3002 // ---------------------------------------------------------
       
  3003 // CSpdiaContainer::UpdateIndexDataL
       
  3004 //
       
  3005 // ---------------------------------------------------------
       
  3006 //
       
  3007 
       
  3008 TBool CSpeedDialPrivate::UpdateIndexDataL(TInt aIndex)
       
  3009     {
       
  3010 	CFbsBitmap* bitmap,*mask;
       
  3011 	bitmap = NULL;
       
  3012 	mask= NULL;
       
  3013 	MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
  3014 	
       
  3015 
       
  3016     TSpdiaIndexDataVPbk& data = (*iSdmArray)[aIndex];
       
  3017     delete (*iIconArray)[aIndex];
       
  3018     (*iIconArray)[aIndex] = NULL;
       
  3019     TFileName bmpPath(iBmpPath);
       
  3020 
       
  3021 	if(	User::Language() == ELangHindi )
       
  3022 	{
       
  3023 		AknsUtils::CreateIconL(skinInstance, (*iDialSkinBmp)[aIndex],bitmap,mask,bmpPath,iDialHindiBmp[aIndex],  iDialHindiBmpMask[aIndex] );
       
  3024 	}
       
  3025 	else
       
  3026 	{
       
  3027 		AknsUtils::CreateIconL(skinInstance, (*iDialSkinBmp)[aIndex],bitmap,mask,bmpPath,iDialBmp[aIndex],  iDialBmpMask[aIndex] );
       
  3028 	}
       
  3029 	(*iIconArray)[aIndex] = CGulIcon::NewL(bitmap,mask);
       
  3030 	
       
  3031 	
       
  3032 	
       
  3033 	MVPbkStoreContact* aContact = data.Contact();
       
  3034 
       
  3035     data.ResetThumbIndex();
       
  3036     if (CreateIndexIconL(aIndex, data, ETrue))
       
  3037         {
       
  3038         
       
  3039     	if (iImageManager)
       
  3040     	{
       
  3041     		data.SetImageOperation( iImageManager->GetImageAsyncL(NULL,*aContact,*iThumbNailFieldType,(*this) ) );
       
  3042     	}
       
  3043         }
       
  3044     else
       
  3045         {
       
  3046         ChangeIndexDataL(aIndex, data);
       
  3047         iGrid->DrawNow();
       
  3048         }
       
  3049     return ETrue;
       
  3050     }
       
  3051    
       
  3052 
       
  3053 // ---------------------------------------------------------
       
  3054 // CSpdiaContainer::CreateIndexIconL
       
  3055 //
       
  3056 // ---------------------------------------------------------
       
  3057 //
       
  3058 TBool CSpeedDialPrivate::CreateIndexIconL(TInt aIndex,
       
  3059                  TSpdiaIndexDataVPbk& aSdmData, TBool aSetUpdateThumb)
       
  3060     {
       
  3061     TBool existThumb(EFalse);
       
  3062 
       
  3063   	if (aSdmData.Contact() != NULL)
       
  3064     {
       
  3065 	    TInt fieldId = -1;	   
       
  3066 	    
       
  3067 	    MVPbkStoreContactField* field = (*iSdmArray)[aIndex].Field();	
       
  3068 		if(field)
       
  3069 		{
       
  3070 			fieldId = field->BestMatchingFieldType()->FieldTypeResId();
       
  3071 		}
       
  3072 	    aSdmData.SetIconIndex(FindIconIndex(fieldId, field ));     
       
  3073 	   
       
  3074 		// check for the functionality, why he is checking has thumbnail before adding
       
  3075 		
       
  3076 		if (iImageManager->HasImage(*aSdmData.Contact(),*iThumbNailFieldType))
       
  3077 		{
       
  3078 			existThumb = ETrue;
       
  3079 	        if (aSetUpdateThumb)
       
  3080 	        {
       
  3081 	            aSdmData.SetLastThumb(ETrue);
       
  3082 	        }
       
  3083 	        aSdmData.SetThumbIndex(aIndex, NULL);
       
  3084 	    }
       
  3085 	    else
       
  3086 	    {
       
  3087 	    	aSdmData.SetThumbIndex(-1, NULL);
       
  3088 	    }
       
  3089 	    
       
  3090     }
       
  3091          
       
  3092     return existThumb;
       
  3093     }
       
  3094 
       
  3095 // ---------------------------------------------------------
       
  3096 // CSpdiaContainer::ChangeIndexDataL
       
  3097 //
       
  3098 // ---------------------------------------------------------
       
  3099 //
       
  3100 void CSpeedDialPrivate::ChangeIndexDataL(
       
  3101     TInt aIndex,
       
  3102     const TSpdiaIndexDataVPbk& aSdmData )
       
  3103     {
       
  3104     CDesCArray* array = STATIC_CAST(CDesCArray*,
       
  3105                         iGrid->Model()->ItemTextArray());
       
  3106     HBufC* des = ItemDescriptorLC(aIndex, aSdmData);
       
  3107     array->Delete(aIndex);
       
  3108     array->InsertL(aIndex, *des);
       
  3109     CleanupStack::PopAndDestroy(); // des
       
  3110     }
       
  3111     
       
  3112     
       
  3113 // ---------------------------------------------------------
       
  3114 // CSpeedDialPrivate::FindIconIndex
       
  3115 //
       
  3116 // ---------------------------------------------------------
       
  3117 //
       
  3118 
       
  3119 TInt CSpeedDialPrivate::FindIconIndex( TInt aId, MVPbkStoreContactField* aField ) //const
       
  3120     {
       
  3121     TInt index(KNullIndexData);
       
  3122     
       
  3123 	// If impp field, find xSP icon info from helper
       
  3124     if ( aField && ( aId == R_VPBK_FIELD_TYPE_IMPP ) )
       
  3125     	{
       
  3126     	TPtrC scheme = MVPbkContactFieldUriData::Cast( aField->FieldData()).Scheme();
       
  3127     	           	
       
  3128     	const TInt count = ixspIconInfoArray.Count(); 
       
  3129     	for ( TInt i=0; i < count; i++ )
       
  3130     		{
       
  3131     		if ( !scheme.CompareF( ixspIconInfoArray[i].LableText() ) )
       
  3132     			{
       
  3133     			index = ixspIconInfoArray[i].IconIndex();
       
  3134     			break;
       
  3135     			}
       
  3136     		}
       
  3137     	}
       
  3138     // If not impp field, calculate icon index as below
       
  3139     else
       
  3140     	{
       
  3141         for (TInt n(0); index == KNullIndexData && n < (sizeof KFieldIds/sizeof KFieldIds[0]); ++n)
       
  3142             {
       
  3143             if ((TUint)aId == KFieldIds[n] )
       
  3144                {
       
  3145                index = n + iSdmCount;
       
  3146                }
       
  3147             }
       
  3148     	}
       
  3149     return index;
       
  3150     }
       
  3151     
       
  3152 
       
  3153 // ---------------------------------------------------------
       
  3154 // CSpdiaContainer::ItemDescriptorL
       
  3155 //
       
  3156 // ---------------------------------------------------------
       
  3157 //
       
  3158 HBufC* CSpeedDialPrivate::ItemDescriptorLC(TInt aIndex,
       
  3159                             const TSpdiaIndexDataVPbk& aSdmData)
       
  3160     {
       
  3161     HBufC* des = NULL;
       
  3162     if (aSdmData.Contact() != NULL)
       
  3163         {
       
  3164         des = CreateItemDescriptorLC(aSdmData);
       
  3165         }
       
  3166     else
       
  3167         {
       
  3168         des = HBufC::NewLC(KNullCell.iTypeLength);
       
  3169         des->Des().Format(KNullCell, aIndex);
       
  3170         }
       
  3171     return des;
       
  3172     }
       
  3173     
       
  3174 // ---------------------------------------------------------
       
  3175 // CSpdiaContainer::SetItemDataL
       
  3176 //
       
  3177 // ---------------------------------------------------------
       
  3178 //
       
  3179 void CSpeedDialPrivate::SetItemDataL(CDesCArray& aArray)
       
  3180     {
       
  3181     for (TInt loop(0); loop < iSdmCount; loop++)
       
  3182         {
       
  3183         TSpdiaIndexDataVPbk& data = (*iSdmArray)[loop];
       
  3184 
       
  3185         aArray.AppendL(ItemDescriptorLC(loop, data)->Des());
       
  3186         CleanupStack::PopAndDestroy(); // des
       
  3187         }
       
  3188     }
       
  3189     
       
  3190 TBool CSpeedDialPrivate::CheckSpaceBelowCriticalLevelL()
       
  3191     {
       
  3192     TBool retcode(EFalse);
       
  3193 
       
  3194     if (SysUtil::FFSSpaceBelowCriticalLevelL(&(iCoeEnv->FsSession())))
       
  3195         {
       
  3196         CErrorUI* errorUi = CErrorUI::NewLC();
       
  3197         errorUi->ShowGlobalErrorNoteL(KErrDiskFull);
       
  3198         CleanupStack::PopAndDestroy(); // errorUi
       
  3199         retcode = ETrue;
       
  3200         }
       
  3201     return retcode;
       
  3202     }
       
  3203 
       
  3204 // ---------------------------------------------------------
       
  3205 // CSpeedDialPrivate::GetThumbnailSize()
       
  3206 // Gets actual size of thumbnial to be drawn
       
  3207 // ---------------------------------------------------------
       
  3208 //
       
  3209 TSize CSpeedDialPrivate::GetThumbnailSize()
       
  3210 {
       
  3211 	TRect mainPaneRect ;
       
  3212     TRect statusPaneRect;
       
  3213     TInt  varient =0;
       
  3214 
       
  3215 	if (Layout_Meta_Data::IsLandscapeOrientation())
       
  3216 	{
       
  3217 	 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainPaneRect);
       
  3218 	 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStatusPane,statusPaneRect);
       
  3219 	 mainPaneRect.iTl = statusPaneRect.iTl;
       
  3220 	 mainPaneRect.iBr.iY = mainPaneRect.iBr.iY - statusPaneRect.iTl.iY;
       
  3221 	 varient =1;
       
  3222 	}
       
  3223 	else
       
  3224 	{
       
  3225 	 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainPaneRect);
       
  3226 	 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStatusPane,statusPaneRect);
       
  3227 	 mainPaneRect.iTl= statusPaneRect.iTl;
       
  3228 	}
       
  3229 		
       
  3230 	TAknLayoutRect mainGridPaneRect;
       
  3231 	TAknLayoutRect gridPaneRect;
       
  3232 	TAknLayoutRect cellPaneRect;
       
  3233 	TAknLayoutRect thumbPaneRect;
       
  3234 	
       
  3235 	mainGridPaneRect.LayoutRect(mainPaneRect,AknLayoutScalable_Apps::main_qdial_pane());//main grid pane
       
  3236 	gridPaneRect.LayoutRect(mainGridPaneRect.Rect(),AknLayoutScalable_Apps::grid_qdial_pane());//main grid pane
       
  3237 	cellPaneRect.LayoutRect(gridPaneRect.Rect(),AknLayoutScalable_Apps::cell_qdial_pane(0,0));
       
  3238 	thumbPaneRect.LayoutRect(cellPaneRect.Rect(),AknLayoutScalable_Apps::thumbnail_qdial_pane(varient));
       
  3239 
       
  3240 	return thumbPaneRect.Rect().Size();
       
  3241 
       
  3242 }
       
  3243 	
       
  3244 
       
  3245 // ---------------------------------------------------------
       
  3246 // CSpeedDialPrivate::ThumbType
       
  3247 // An interface for accessing index data array.
       
  3248 // ---------------------------------------------------------
       
  3249 //
       
  3250 TInt CSpeedDialPrivate::ThumbType(TInt aIndex) const
       
  3251     {
       
  3252     return ConvThumbType((*iSdmArray)[aIndex].ThumbSize());
       
  3253     }
       
  3254     
       
  3255 // ---------------------------------------------------------
       
  3256 // CSpeedDialPrivate::ThumbSize
       
  3257 // An interface for accessing index data array.
       
  3258 // ---------------------------------------------------------
       
  3259 //
       
  3260 TSize CSpeedDialPrivate::ThumbSize(TInt aIndex) const
       
  3261     {
       
  3262     return (*iSdmArray)[aIndex].ThumbSize();
       
  3263     }
       
  3264     
       
  3265 // ---------------------------------------------------------
       
  3266 // CSpdiaContainer::ConvThumbType
       
  3267 // Returns
       
  3268 //      EtnVGA  : 640 x 480 40 x 30 VGA
       
  3269 //      EtnVGA90: 480 x 640 30 x 40 VGA turned
       
  3270 //      EtnCIF  : 352 x 288 44 x 36 CIF
       
  3271 //      EtnCIF90: 288 x 352 36 x 44 CIF turned
       
  3272 //      EtnCOM  : othre
       
  3273 // ---------------------------------------------------------
       
  3274 //
       
  3275 TInt CSpeedDialPrivate::ConvThumbType(const TSize& aSize) const
       
  3276     {
       
  3277 	// Scalable UI
       
  3278 	TAknWindowLineLayout  vga;
       
  3279 	TAknWindowLineLayout  cif;
       
  3280 	if( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
  3281 	{
       
  3282 	 vga = AknLayoutScalable_Apps::popup_phob_thumbnail_window_g2().LayoutLine();
       
  3283 	 cif = AknLayoutScalable_Apps::popup_phob_thumbnail_window_g1().LayoutLine();//image
       
  3284 
       
  3285 	}
       
  3286 	else
       
  3287 	{
       
  3288 	 vga = AppLayout::Thumbnail_pop_up_window_elements_Line_1();
       
  3289 	 cif = AppLayout::Thumbnail_pop_up_window_elements_Line_3();
       
  3290 
       
  3291 	}
       
  3292     TInt type(CSpdiaGridVPbk::EtnCOM);
       
  3293 
       
  3294     if (aSize.iWidth == cif.iH//SDM_TN_CIF_HEIGHT
       
  3295             && aSize.iHeight == cif.iW)// SDM_TN_CIF_WIDTH)
       
  3296         {
       
  3297         type = CSpdiaGridVPbk::EtnCIF90;
       
  3298         }
       
  3299     else if (aSize.iWidth == cif.iW &&//SDM_TN_CIF_WIDTH &&
       
  3300                     aSize.iHeight ==  cif.iH)//SDM_TN_CIF_HEIGHT)
       
  3301         {
       
  3302         type = CSpdiaGridVPbk::EtnCIF;
       
  3303         }
       
  3304     else if (aSize.iWidth == vga.iH &&//SDM_TN_VGA_HEIGHT &&
       
  3305                     aSize.iHeight == vga.iW )//SDM_TN_VGA_WIDTH)
       
  3306         {
       
  3307         type = CSpdiaGridVPbk::EtnVGA90;
       
  3308         }
       
  3309     else if (aSize.iWidth == vga.iW &&//SDM_TN_VGA_WIDTH &&
       
  3310                     aSize.iHeight == vga.iH)//SDM_TN_VGA_HEIGHT)
       
  3311         {
       
  3312         type = CSpdiaGridVPbk::EtnVGA;
       
  3313         }
       
  3314 
       
  3315     return type;
       
  3316     }
       
  3317 
       
  3318 // ---------------------------------------------------------
       
  3319 // CSpdiaContainer::AppendThumbnail
       
  3320 // output \tThumbnail\ticon
       
  3321 // ---------------------------------------------------------
       
  3322 //
       
  3323 void CSpeedDialPrivate::AppendThumbnail(
       
  3324     const TSpdiaIndexDataVPbk& aSdmData,
       
  3325     TPtr& aText,
       
  3326     TBool aFixedLocation )
       
  3327     {
       
  3328     if (!aFixedLocation)
       
  3329         {
       
  3330         aText.Append(KDesTab2);
       
  3331         return;
       
  3332         }
       
  3333 
       
  3334     aText.Append(KDesTab);
       
  3335     if ( aSdmData.ThumbIndex() >= 0 && aSdmData.ThumbSize().iWidth > 0 )
       
  3336         {
       
  3337         aText.AppendNum(aSdmData.ThumbIndex());
       
  3338         }
       
  3339 
       
  3340     aText.Append(KDesTab);
       
  3341     if (aSdmData.IconIndex() >= 0)
       
  3342         {
       
  3343         aText.AppendNum(aSdmData.IconIndex());
       
  3344         }
       
  3345     }
       
  3346 	
       
  3347 
       
  3348 
       
  3349 
       
  3350 
       
  3351 // ---------------------------------------------------------
       
  3352 // CSpeedDialPrivate::AssignSpeedDial
       
  3353 //
       
  3354 // ---------------------------------------------------------
       
  3355 //
       
  3356 
       
  3357 TBool CSpeedDialPrivate::AssignSpeedDialL(TInt aIndex)
       
  3358 {
       
  3359 	TBool aReturn (EFalse);
       
  3360 	
       
  3361 	MVPbkContactOperationBase* operation = NULL;
       
  3362 
       
  3363 	iSpeedDial->SetIndex(aIndex+1);	
       
  3364 	
       
  3365 	iOperationComplete = EFalse;
       
  3366 	(*iSdmArray)[aIndex].Contact()->LockL(*this);
       
  3367 	
       
  3368 	while(!iOperationComplete)
       
  3369 	{
       
  3370 		Wait();
       
  3371 	}
       
  3372 	if(iError == KErrNone)
       
  3373 	{
       
  3374 		
       
  3375 		MVPbkStoreContactField* field = (*iSdmArray)[aIndex].Field();
       
  3376 		iOperationComplete = EFalse;
       
  3377 		
       
  3378 		if( field != NULL)
       
  3379 		{
       
  3380 			operation = iAttributeManager->SetFieldAttributeL( *field, *iSpeedDial, ( *this ) );
       
  3381 		}
       
  3382 	
       
  3383 		if(operation != NULL)
       
  3384 		{
       
  3385 			(*iSdmArray)[aIndex].SetOperation(operation,TSpdiaIndexDataVPbk::OPERATION_ASSIGN);
       
  3386 			while(!iOperationComplete)
       
  3387 			{
       
  3388 				Wait();
       
  3389 			}
       
  3390 		
       
  3391 		}
       
  3392 		if(iError == KErrNone)
       
  3393 		{
       
  3394 			aReturn = ETrue;
       
  3395 		}
       
  3396 	}
       
  3397 
       
  3398 	return aReturn;		
       
  3399 }
       
  3400 
       
  3401 
       
  3402 
       
  3403 // ---------------------------------------------------------
       
  3404 // CSpeedDialPrivate::RemoveSpeedDial
       
  3405 //
       
  3406 // ---------------------------------------------------------
       
  3407 //
       
  3408 
       
  3409 TBool CSpeedDialPrivate::RemoveSpeedDialL(TInt aIndex)
       
  3410 {
       
  3411 	TBool aReturn (EFalse);
       
  3412 	
       
  3413 	if((*iSdmArray)[aIndex].Field() != NULL)
       
  3414 	{
       
  3415 		iError = KErrNone;
       
  3416 		
       
  3417 		iOperationComplete = EFalse;
       
  3418 		iSpeedDial->SetIndex(aIndex+1);
       
  3419 		(*iSdmArray)[aIndex].Contact()->LockL(*this);
       
  3420 			
       
  3421 		while(!iOperationComplete)
       
  3422 		{
       
  3423 				Wait();
       
  3424 		}
       
  3425 		
       
  3426 	if(iError == KErrNone)
       
  3427 		{
       
  3428 			iOperationComplete = EFalse;
       
  3429 			MVPbkContactOperationBase* operation = iAttributeManager->RemoveFieldAttributeL(
       
  3430 													*((*iSdmArray)[aIndex].Field()), *iSpeedDial, (*this));
       
  3431 			
       
  3432 			if(operation)
       
  3433 			{
       
  3434 				
       
  3435 				(*iSdmArray)[aIndex].SetOperation(operation,TSpdiaIndexDataVPbk::OPERATION_REMOVE);
       
  3436 			
       
  3437 				while(!iOperationComplete)
       
  3438 				{
       
  3439 					Wait();
       
  3440 				}
       
  3441 
       
  3442 			}
       
  3443 			
       
  3444 			if(iError == KErrNone)
       
  3445 			{
       
  3446 				aReturn = ETrue;
       
  3447 			}
       
  3448 		}
       
  3449 	}
       
  3450 
       
  3451 	return aReturn;
       
  3452 }
       
  3453 
       
  3454 // ---------------------------------------------------------
       
  3455 // CSpeedDialPrivate::ContactTitleL
       
  3456 //
       
  3457 // ---------------------------------------------------------
       
  3458 //
       
  3459 
       
  3460 EXPORT_C HBufC* CSpeedDialPrivate::ContactTitleL( MVPbkBaseContact* aContact, TBool aUnnamed )
       
  3461 {
       
  3462 
       
  3463 
       
  3464 	HBufC* title = NULL;
       
  3465 	
       
  3466 	if (aContact != NULL)
       
  3467 	{
       
  3468 		CPbk2SortOrderManager* sortOrderManager = CPbk2SortOrderManager::NewL( iContactManager->FieldTypes() );
       
  3469        
       
  3470 	    MPbk2ContactNameFormatter* nameFormatter = Pbk2ContactNameFormatterFactory::CreateL(
       
  3471 	                        iContactManager->FieldTypes(), 
       
  3472 	                        *sortOrderManager );
       
  3473         title = nameFormatter->GetContactTitleOrNullL( aContact->Fields(), KContactFormattingFlags );
       
  3474 	    
       
  3475 	    if (title == NULL && aUnnamed)
       
  3476 	    {
       
  3477 	    	title = nameFormatter->UnnamedText().AllocL();	
       
  3478 	    }
       
  3479 	    
       
  3480 	    delete sortOrderManager;
       
  3481 	    delete nameFormatter;
       
  3482 	}
       
  3483   
       
  3484     return title;
       
  3485                         
       
  3486 }
       
  3487 
       
  3488 // ---------------------------------------------------------
       
  3489 // CSpeedDialPrivate::Release
       
  3490 //
       
  3491 // ---------------------------------------------------------
       
  3492 //
       
  3493 void CSpeedDialPrivate::Release(  )
       
  3494      {
       
  3495      
       
  3496     
       
  3497      if( iWait->IsStarted() )
       
  3498          {
       
  3499          iWait->AsyncStop();
       
  3500          }
       
  3501      }
       
  3502    
       
  3503 // ---------------------------------------------------------
       
  3504 // CSpeedDialPrivate::Wait
       
  3505 //
       
  3506 // ---------------------------------------------------------
       
  3507 //
       
  3508 void CSpeedDialPrivate::Wait()
       
  3509 {
       
  3510    if( !(iWait->IsStarted()) ) 
       
  3511     	iWait->Start();
       
  3512 
       
  3513 }
       
  3514 
       
  3515 // ---------------------------------------------------------
       
  3516 // CSpeedDialPrivate::WaitFetchMail
       
  3517 //
       
  3518 // ---------------------------------------------------------
       
  3519 //
       
  3520 void CSpeedDialPrivate::WaitFetchMail()
       
  3521     {
       
  3522     if ( !( iWaitFetchmail->IsStarted() ) )
       
  3523         {
       
  3524         iWaitFetchmail->Start();
       
  3525         }
       
  3526     }
       
  3527 
       
  3528 // ---------------------------------------------------------
       
  3529 // CSpeedDialPrivate::ReleaseFetchMail
       
  3530 //
       
  3531 // ---------------------------------------------------------
       
  3532 //
       
  3533 void CSpeedDialPrivate::ReleaseFetchMail()
       
  3534     {
       
  3535     if ( iWaitFetchmail->IsStarted() )
       
  3536         {
       
  3537         iWaitFetchmail->AsyncStop();
       
  3538         }
       
  3539     }
       
  3540 
       
  3541 // ---------------------------------------------------------
       
  3542 // CSpeedDialPrivate::Cancel
       
  3543 // To cancel the aiw event
       
  3544 // ---------------------------------------------------------
       
  3545 //
       
  3546 TBool CSpeedDialPrivate::Cancel()
       
  3547 {
       
  3548 	if(!iOperationComplete)
       
  3549 	{
       
  3550 		iOperationComplete = ETrue;
       
  3551 	}
       
  3552 	if(iQueryDialog)
       
  3553 	{
       
  3554 		delete iQueryDialog;
       
  3555 		iQueryDialog = NULL;
       
  3556 	}
       
  3557     if ( iServiceHandler )
       
  3558         {
       
  3559         TRAP_IGNORE(
       
  3560                 {
       
  3561                 CAiwGenericParamList& inParamList =  iServiceHandler->InParamListL();
       
  3562                 CAiwGenericParamList& outParamList =  iServiceHandler->OutParamListL();
       
  3563                 iServiceHandler->ExecuteServiceCmdL(
       
  3564                     KAiwCmdAssign, 
       
  3565                     inParamList,
       
  3566                     outParamList,
       
  3567                     KAiwOptCancel, NULL );
       
  3568                 }
       
  3569             )
       
  3570         }
       
  3571     
       
  3572     Release();
       
  3573     iCancelFlag = ETrue;
       
  3574     return ETrue;
       
  3575 }
       
  3576 
       
  3577 // ---------------------------------------------------------
       
  3578 // CSpeedDialPrivate::GetWait
       
  3579 // Monitor iWait
       
  3580 // ---------------------------------------------------------
       
  3581 //
       
  3582 EXPORT_C CActiveSchedulerWait* CSpeedDialPrivate::GetWait()
       
  3583  {
       
  3584   return iWait;	
       
  3585  }
       
  3586 
       
  3587 // ---------------------------------------------------------
       
  3588 // CSpeedDialPrivate::ReplaceNonGraphicCharacters
       
  3589 // To replace nongraphic characters (e.g.:- newline)
       
  3590 // ---------------------------------------------------------
       
  3591 //
       
  3592 void CSpeedDialPrivate::ReplaceNonGraphicCharacters( TDes& aText, TText aChar )
       
  3593     {
       
  3594     const TInt len = aText.Length();
       
  3595 
       
  3596     const TUint KPbkZWSCharacter = 0x200B;
       
  3597     const TUint KPbkZWNJCharacter = 0x200C;
       
  3598 
       
  3599     // Zero Width Space character
       
  3600     const TChar zwsChar( KPbkZWSCharacter );
       
  3601     // Zero Width Non-Joiner character
       
  3602     const TChar zwnjChar( KPbkZWNJCharacter );
       
  3603 
       
  3604     for ( TInt i=0; i < len; ++i )
       
  3605         {
       
  3606         if ( !TChar(aText[i]).IsGraph() &&
       
  3607              ( (zwsChar != aText[i]) && (zwnjChar != aText[i]) ) )
       
  3608             {
       
  3609             // If non-graphic char is specified in ZWSCharacter,
       
  3610             // it will not be replaced. Otherwise replace non-graphic
       
  3611             // character with aChar.
       
  3612              aText[i] = aChar;
       
  3613 	        }
       
  3614         }
       
  3615 
       
  3616     aText.Trim();
       
  3617 }
       
  3618 
       
  3619 // ---------------------------------------------------------
       
  3620 // CSpeedDialPrivate::SetRefreshObserver
       
  3621 // Set refresh observer.
       
  3622 // ---------------------------------------------------------
       
  3623 //
       
  3624 EXPORT_C  void CSpeedDialPrivate::SetRefreshObserver( MRefreshObserver* aObserver )
       
  3625     {
       
  3626     iRefreshObserver = aObserver;
       
  3627     }
       
  3628 
       
  3629 // ---------------------------------------------------------
       
  3630 // CSpeedDialPrivate::SetCurrentGridIndex
       
  3631 // set the currentindex
       
  3632 // ---------------------------------------------------------
       
  3633 //
       
  3634 EXPORT_C void CSpeedDialPrivate::SetCurrentGridIndex( TInt aCurrentGridIndex )
       
  3635  	{
       
  3636 	iCurrentIndex = aCurrentGridIndex;
       
  3637 	}
       
  3638 
       
  3639 
       
  3640 // ---------------------------------------------------------
       
  3641 // CSpeedDialPrivate::SetGridDataAsNull
       
  3642 // Set iGrid and iIconArray as Null
       
  3643 // ---------------------------------------------------------
       
  3644 //
       
  3645 EXPORT_C void CSpeedDialPrivate::SetGridDataAsNull()
       
  3646 	{
       
  3647 	iGrid = NULL;
       
  3648 	iIconArray = NULL;
       
  3649 	}
       
  3650 // ---------------------------------------------------------
       
  3651 // CSpeedDialPrivate::SetCurrentGridIndex
       
  3652 // set the currentindex
       
  3653 // ---------------------------------------------------------
       
  3654 //
       
  3655 void CSpeedDialPrivate::ShowNoteL( TInt aResourceId )
       
  3656     {
       
  3657     HBufC* prompt = StringLoader::LoadLC( aResourceId );
       
  3658     CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( EFalse );
       
  3659     dlg->ExecuteLD( *prompt );
       
  3660     CleanupStack::PopAndDestroy(); // prompt
       
  3661     }
       
  3662 // End of the file
       
  3663