serviceproviders/sapi_contacts_vpbk/contactservice/src/contactviewobserver.cpp
changeset 22 fc9cf246af83
parent 19 989d2f495d90
equal deleted inserted replaced
19:989d2f495d90 22:fc9cf246af83
    19 #include <CVPbkContactLinkArray.h>
    19 #include <CVPbkContactLinkArray.h>
    20 #include <MVPbkContactViewBase.h>
    20 #include <MVPbkContactViewBase.h>
    21 
    21 
    22 #include "contactiter.h"
    22 #include "contactiter.h"
    23 #include "contactviewobserver.h"
    23 #include "contactviewobserver.h"
       
    24 #include <MVPbkContactLink.h>
    24 
    25 
    25 
    26 
    26 //---------------------------------------------------------------------------
    27 //---------------------------------------------------------------------------
    27 // Method that gets the links from the view and passes the link array to the 
    28 // Method that gets the links from the view and passes the link array to the 
    28 // iterator.
    29 // iterator.
    29 //---------------------------------------------------------------------------
    30 //---------------------------------------------------------------------------
    30 void CContactViewObserver::SetupContactLinkArrayL(MVPbkContactViewBase& aView )
    31 void CContactViewObserver::SetupContactLinkArrayL(MVPbkContactViewBase& aView )
    31 {
    32 {
    32 	if((iFlag == EContactFilteredView) || ((iFlag == EContactDefaultView) && (iDefaultView)))
    33 	if((iFlag == EContactFilteredView) || ((iFlag == EContactDefaultView) && (iDefaultView)))
    33 		{
    34 		{
    34 		CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewL();
    35         TInt viewCount = aView.ContactCountL();
    35 		CleanupStack::PushL(linkArray);
    36         
    36 		TInt viewCount = aView.ContactCountL();
    37 
    37 		if(viewCount)
    38         if(viewCount)
    38 			{
    39             {
    39 			for(TInt i=0; i < viewCount; i++)
    40             CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewL();
       
    41                                 CleanupStack::PushL(linkArray);
       
    42             RPointerArray<HBufC8> idArray(viewCount);
       
    43             if(iVal == EGetList)
       
    44              {
       
    45              MVPbkContactLink* link = NULL;
       
    46             for(TInt i=0; i < viewCount; i++)
       
    47                  {
       
    48                      
       
    49                      link = aView.CreateLinkLC(i);
       
    50                      linkArray->AppendL(link);
       
    51                      CleanupStack::Pop();
       
    52                  }
       
    53              }
       
    54              else
       
    55                  {
       
    56 				 if(iSortOrder == EDesc)
    40 				 {
    57 				 {
    41 				 linkArray->AppendL(aView.CreateLinkLC(i));
    58                  for(TInt i=(viewCount-1); i >= 0; i--)
    42 				 }
    59                   {
    43 				 
    60                      MVPbkContactLink* link = NULL;
    44 			//Set the params for iterator
    61                      link = aView.CreateLinkLC(i);
    45 			iIter->SetParams(linkArray, *iStoreUri, iSortOrder, iTransId, EContacts, iContactService);
    62                      idArray.AppendL( link->PackLC());
    46 			 
    63                      CleanupStack::Pop();   //PackLC puts every element into cleanup stack
    47 			 //Notify the user				  
    64                      //CleanupStack::PopAndDestroy();
    48 			iCallback->HandleReturnIter(KErrNone, iIter, iTransId);
    65                   }
    49 			 
    66 				  }
    50 			CleanupStack::Pop(viewCount);
    67 				  else 
    51 			}
    68 				  {
       
    69 					for(TInt j=0; j < viewCount; j++)
       
    70                   {
       
    71                      MVPbkContactLink* link = NULL;
       
    72                      link = aView.CreateLinkLC(j);
       
    73                      idArray.AppendL( link->PackLC());
       
    74                      CleanupStack::Pop();   //PackLC puts every element into cleanup stack
       
    75                      //CleanupStack::PopAndDestroy();
       
    76                   }
       
    77 				  }
       
    78                  }
       
    79                  
       
    80                  
       
    81                  
       
    82             if(iVal == EGetList)
       
    83             {
       
    84                 //Set the params for iterator
       
    85                 iIter->SetParams(linkArray, *iStoreUri, iSortOrder, iTransId, EContacts, iContactService);
       
    86                 //Notify the user                
       
    87                 iCallback->HandleReturnIter(KErrNone, iIter, iTransId);
       
    88               //  CleanupStack::Pop(viewCount);   //All Contacts are put in clean up stack. Pop em
       
    89                 CleanupStack::Pop(linkArray);
       
    90                 
       
    91             }
       
    92             else
       
    93             {
       
    94            //iContactService->RequestComplete(iTransId);
       
    95            //Notify the user
       
    96            //iCallback->HandleReturnIter(KErrNone, iIter, iTransId);
       
    97       
       
    98              iCallback->HandleReturnArray(KErrNone, idArray, iTransId);
       
    99              CleanupStack::PopAndDestroy(viewCount);
       
   100              CleanupStack::PopAndDestroy(linkArray);
       
   101              //idArray.Reset();
       
   102              delete iIter;
       
   103             }
       
   104              
       
   105                 
       
   106             }
    52 		else
   107 		else
    53 			{
   108 			{
    54 			//Notify User
   109 			//Notify User
    55 			iCallback->HandleReturnValue(EOpComplete, KErrNotFound, iTransId);	
   110 			iCallback->HandleReturnValue(EOpComplete, KErrNotFound, iTransId);	
    56 			delete iIter;
   111             delete iIter;
    57 			iIter = NULL;
   112 			iIter = NULL;
    58 			}
   113 			}
    59 		CleanupStack::Pop(linkArray);
   114                
    60 		}
   115 		}
    61 }
   116 }
    62 
   117 
    63 
   118 
    64 //---------------------------------------------------------------------------
   119 //---------------------------------------------------------------------------
    82 
   137 
    83 //---------------------------------------------------------------------------
   138 //---------------------------------------------------------------------------
    84 // NewL()
   139 // NewL()
    85 //---------------------------------------------------------------------------
   140 //---------------------------------------------------------------------------
    86 
   141 
    87 CContactViewObserver* CContactViewObserver::NewL( MContactCallback* aCallback, enum TViewFlag aFlag, CContactIter* iIter,CContactService* aContactService,const TDesC& aStoreUri, TOrder aSortOrder, TInt aTransId, CActiveSchedulerWait* aSchedulerWait)
   142 CContactViewObserver* CContactViewObserver::NewL( MContactCallback* aCallback, enum TViewFlag aFlag, CContactIter* iIter, CContactService* aContactService,const TDesC& aStoreUri, TOrder aSortOrder, TInt aTransId, CActiveSchedulerWait* aSchedulerWait, TCmdType val)
    88 {
   143 {
    89     CContactViewObserver* self = new( ELeave ) CContactViewObserver( aStoreUri, aFlag, iIter, aContactService, aCallback, aSortOrder, aTransId, aSchedulerWait);
   144     CContactViewObserver* self = new( ELeave ) CContactViewObserver( aStoreUri, aFlag, iIter,aContactService, aCallback, aSortOrder, aTransId, aSchedulerWait, val);
    90     return self;
   145     return self;
    91 }
   146 }
    92 
   147 
    93 
   148 
    94 //---------------------------------------------------------------------------
   149 //---------------------------------------------------------------------------
    95 // ConstructL()
   150 // ConstructL()
    96 //---------------------------------------------------------------------------
   151 //---------------------------------------------------------------------------
    97     
   152     
    98 
   153 
    99 CContactViewObserver::CContactViewObserver(const TDesC& aStoreUri, enum TViewFlag aFlag, CContactIter* aIter, CContactService* aContactService, MContactCallback* aCallback, TOrder aSortOrder, TInt aTransId, CActiveSchedulerWait* aSchedulerWait )
   154 CContactViewObserver::CContactViewObserver(const TDesC& aStoreUri, enum TViewFlag aFlag, CContactIter* aIter, CContactService* aContactService, MContactCallback* aCallback, TOrder aSortOrder, TInt aTransId, CActiveSchedulerWait* aSchedulerWait, TCmdType val )
   100 :	iStoreUri (&aStoreUri),
   155 :	iStoreUri (&aStoreUri),
   101 	iFlag (aFlag),
   156 	iFlag (aFlag),
   102 	iIter (aIter),
   157 	iIter (aIter),
   103 	iCallback (aCallback),
   158 	iCallback (aCallback),
   104 	iSortOrder (aSortOrder),
   159 	iSortOrder (aSortOrder),
   105 	iTransId (aTransId),
   160 	iTransId (aTransId),
   106 	iDefaultView (EFalse),
   161 	iDefaultView (EFalse),
   107 	iSchedulerWait(aSchedulerWait),
   162 	iSchedulerWait(aSchedulerWait),
   108 	iContactService(aContactService)
   163 	iContactService(aContactService),
       
   164 	iVal(val)
   109 {
   165 {
   110 }
   166 }
   111 
   167 
   112 /*
   168 /*
   113 -------------------------------------------------------------------------------------
   169 -------------------------------------------------------------------------------------