serviceproviders/sapi_calendar/calendarservice/src/calendargetlist.cpp
changeset 22 fc9cf246af83
child 24 f4292e0e20df
equal deleted inserted replaced
19:989d2f495d90 22:fc9cf246af83
       
     1 /*
       
     2 * Copyright (c) 2009 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 the License "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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //System Includes
       
    20 #include <e32cmn.h> 			//for RPointerArray
       
    21 #include <calsession.h>			//For CCalSession
       
    22 #include <calentryview.h>
       
    23 #include <CalenInterimUtils2.h>
       
    24 #include <s32mem.h>
       
    25 #include <s32file.h>
       
    26 #include <e32base.h>
       
    27 #include <calinstanceview.h>
       
    28 #include <calinstance.h>
       
    29 #include <calentry.h>
       
    30 //User Include
       
    31 #include "calendarheader.h"
       
    32 #include "calendarconstants.h"
       
    33 #include "asyncreqobserver.h"
       
    34 #include "calendargetlist.h"
       
    35 #include "calendarheader.h"
       
    36 
       
    37 void CleanupCCalEntryArray(TAny* aPointer);
       
    38 void CleanupCCalInstanceArray(TAny* aPointer);
       
    39 
       
    40 // --------------------------------------------------------------------------------------------------------
       
    41 // Static Method which either returns the Two Phase constructed Object or Leave 
       
    42 // NOTE: Ownership of any of the parameters is not taken through this function call
       
    43 // NOTE: Therefore the User of this function needs to take care of neccessary cleanup of passed parameters
       
    44 // --------------------------------------------------------------------------------------------------------
       
    45 //
       
    46 CCalendarGetList* CCalendarGetList::NewL ( CCalendarSessionInfo* aCalSessionInfo, 
       
    47                                             const TDesC8& aGuid, 
       
    48 											CAsyncRequestObserver* aAsyncRequestObserver,
       
    49 											MCalCallbackBase* aCallBack )
       
    50 	{
       
    51 	CCalendarGetList* self = new (ELeave) CCalendarGetList( aCalSessionInfo, aAsyncRequestObserver, aCallBack );
       
    52 	
       
    53     CleanupStack::PushL(self);
       
    54     
       
    55     self->ConstructL( aGuid );
       
    56     
       
    57     CleanupStack::Pop(self); 
       
    58     
       
    59     return self;
       
    60 	}	
       
    61 // --------------------------------------------------------------------------------------------------------
       
    62 // Static Method which either returns the Two Phase constructed Object or Leave 
       
    63 // NOTE: Ownership of any of the parameters is not taken through this function call
       
    64 // NOTE: Therefore the User of this function needs to take care of neccessary cleanup of passed parameters
       
    65 // --------------------------------------------------------------------------------------------------------
       
    66 //
       
    67 CCalendarGetList* CCalendarGetList::NewL ( CCalendarSessionInfo* aCalSessionInfo, 
       
    68                                             const TCalLocalUid aLocalUid, 
       
    69                                             CAsyncRequestObserver* aAsyncRequestObserver,
       
    70                                             MCalCallbackBase* aCallBack )
       
    71     {
       
    72     CCalendarGetList* self = new (ELeave) CCalendarGetList( aCalSessionInfo, aAsyncRequestObserver, aCallBack );
       
    73     
       
    74     CleanupStack::PushL(self);
       
    75     
       
    76     self->ConstructL( aLocalUid );
       
    77     
       
    78     CleanupStack::Pop(self); 
       
    79     
       
    80     return self;
       
    81     }   
       
    82 // --------------------------------------------------------------------------------------------------------
       
    83 // Static Method which either returns the Two Phase constructed Object or Leave 
       
    84 // NOTE: Ownership of any of the parameters is not taken through this function call
       
    85 // NOTE: Therefore the User of this function needs to take care of neccessary cleanup of passed parameters
       
    86 // --------------------------------------------------------------------------------------------------------
       
    87 //
       
    88 CCalendarGetList* CCalendarGetList::NewL ( CCalendarSessionInfo* aCalSessionInfo, 
       
    89                                             CCalendarFilter* aFilter,  
       
    90 											CAsyncRequestObserver* aAsyncRequestObserver,
       
    91 											MCalCallbackBase* aCallBack )
       
    92 	{
       
    93 	CCalendarGetList* self = new (ELeave) CCalendarGetList( aCalSessionInfo, aAsyncRequestObserver, aCallBack );
       
    94 	
       
    95     CleanupStack::PushL(self);
       
    96     // Construct filter object which determines the type of get 
       
    97     self->ConstructL( aFilter );
       
    98     
       
    99     CleanupStack::Pop(self); 
       
   100     
       
   101     return self;
       
   102 	}	
       
   103 
       
   104 	
       
   105 // --------------------------------------------------------------------------------------------------------
       
   106 // Destructor.
       
   107 // --------------------------------------------------------------------------------------------------------
       
   108 //
       
   109 CCalendarGetList::~CCalendarGetList()
       
   110 	{
       
   111 	Cancel();	
       
   112 	
       
   113 	delete iFilter;
       
   114 	
       
   115 	delete iGuid;
       
   116 	
       
   117     iEntryList.Reset();
       
   118     iInstanceList.Reset();
       
   119 	}
       
   120 	
       
   121 	
       
   122 // --------------------------------------------------------------------------------------------------------
       
   123 // Constructor.
       
   124 // --------------------------------------------------------------------------------------------------------
       
   125 //
       
   126 CCalendarGetList::CCalendarGetList( CCalendarSessionInfo* aCalSessionInfo, 
       
   127 									CAsyncRequestObserver* aAsyncRequestObserver,
       
   128 									MCalCallbackBase* aCallBack ): 
       
   129 															//CActive( EPriorityStandard ),
       
   130 														  	iSessionInfo (aCalSessionInfo ),
       
   131 														  	iCallBack( aCallBack ),
       
   132 														  	iAsyncRequestObserver(aAsyncRequestObserver)
       
   133 	{
       
   134 
       
   135 	}
       
   136 	
       
   137 	
       
   138 // --------------------------------------------------------------------------------------------------------
       
   139 // 2nd-phased constructor of two phase construction
       
   140 // --------------------------------------------------------------------------------------------------------
       
   141 //
       
   142 void CCalendarGetList::ConstructL( const TDesC8& aGuid )
       
   143 	{	
       
   144    if(aGuid.Length())
       
   145        {
       
   146        iGuid = aGuid.AllocL();// = aGuid ; 
       
   147        iGetListOption = EGetListGUid;
       
   148        }
       
   149 	}
       
   150 
       
   151 void CCalendarGetList::ConstructL( const TCalLocalUid aLocalUid )
       
   152     {   
       
   153    
       
   154     iLocalUid = aLocalUid;    
       
   155     iGetListOption = EGetListLocalUid;
       
   156     }
       
   157 // --------------------------------------------------------------------------------------------------------
       
   158 // GetList implementation
       
   159 // --------------------------------------------------------------------------------------------------------
       
   160 //
       
   161 void CCalendarGetList::ConstructL( CCalendarFilter* aFilter )
       
   162     {   
       
   163    
       
   164     iFilter = CCalendarFilter::NewL();
       
   165     *iFilter = *aFilter;   
       
   166     iGetListOption = EGetListTimeRange;
       
   167     
       
   168     }
       
   169 
       
   170 void CCalendarGetList::GetListL( const TDesC8& aGuid, RPointerArray<CCalEntry>& aEntryList )
       
   171     {
       
   172         iSessionInfo ->EntryView()->FetchL( aGuid, aEntryList );
       
   173     }
       
   174 
       
   175 void CCalendarGetList::GetListL(const TCalLocalUid aLocalUid, RPointerArray<CCalEntry>& aEntryList )
       
   176     {
       
   177   CCalEntry* entry = iSessionInfo ->EntryView()->FetchL( aLocalUid );
       
   178                 if( entry )
       
   179                         {
       
   180                         aEntryList.Append( entry );
       
   181                         }
       
   182     }
       
   183 
       
   184 void CCalendarGetList::GetListL( RPointerArray<CCalInstance>& aInstanceList )
       
   185     {
       
   186  //   iInstanceList = aInstanceList;
       
   187     CalCommon::TCalTimeRange range =  iFilter->TimeRange();
       
   188     if( (range.EndTime().TimeLocalL()) < (range.StartTime().TimeLocalL()) )
       
   189         User::Leave( KErrArgument );
       
   190     if ( iFilter->FilterText().Length() )
       
   191         {
       
   192         // Search and return all instances which match filter text and time range
       
   193         CCalInstanceView::TCalSearchParams searchParam( iFilter->FilterText(), CalCommon::EFoldedTextSearch );
       
   194         iSessionInfo ->InstanceView()->FindInstanceL( aInstanceList, 
       
   195                                                     iFilter->FilterType(), 
       
   196                                                     iFilter->TimeRange(), searchParam ) ;
       
   197         }
       
   198     else
       
   199         {
       
   200         // Search and return all instances which match filter type and time range
       
   201         iSessionInfo ->InstanceView()->FindInstanceL( aInstanceList, 
       
   202                                                     iFilter->FilterType(), 
       
   203                                                     iFilter->TimeRange() ) ;
       
   204         }   
       
   205     }
       
   206 
       
   207 void CCalendarGetList::GetListL()
       
   208     {
       
   209     if( iCallBack )    // making call as asynchronous
       
   210         {
       
   211         if(!iAsyncRequestObserver ) 
       
   212         User::Leave( KErrArgument );
       
   213     
       
   214         CActiveScheduler::Add ( this );
       
   215     
       
   216         ActivateRequest( KErrNone );
       
   217         }
       
   218     }
       
   219 // --------------------------------------------------------------------------------------------------------
       
   220 // Notifies callback the result for asynchronous request.
       
   221 // --------------------------------------------------------------------------------------------------------
       
   222 //
       
   223 void CCalendarGetList::NotifyRequestResult( TInt aReason )
       
   224     {
       
   225 
       
   226     if ( iCallBack )
       
   227         {
       
   228         iAsyncRequestObserver->RequestComplete( iCallBack->iTransactionId );
       
   229         
       
   230          if( iGetListOption == EGetListGUid )
       
   231             {
       
   232             TRAPD( err, iCallBack->NotifyResultL( aReason, ( TAny * )( & iEntryList )));    
       
   233             }
       
   234         else if( iGetListOption == EGetListLocalUid )
       
   235             {
       
   236             TRAPD( err, iCallBack->NotifyResultL( aReason, ( TAny * )( & iEntryList )));    
       
   237             }
       
   238         else
       
   239             {
       
   240             TRAPD( err, iCallBack->NotifyResultL( aReason, ( TAny * )( & iInstanceList ))); 
       
   241             }
       
   242         }
       
   243     if ( aReason != KErrCancel )
       
   244         delete this; 
       
   245     }
       
   246 // ---------------------------------------------------------------------------
       
   247 // Inherited from CActive class 
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 void CCalendarGetList::DoCancel()
       
   251 	{
       
   252 	
       
   253 	NotifyRequestResult( KErrCancel );
       
   254 	}
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // Inherited from CActive class 
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 void CCalendarGetList::RunL()
       
   261 	{
       
   262 	TInt err = iStatus.Int();
       
   263 
       
   264 	if ( err == KErrNone )
       
   265 		{
       
   266         // Performs the actual delete depending on the parameters set
       
   267         TRAP(err, StartFetchingL());
       
   268 		}
       
   269 		
       
   270 	NotifyRequestResult( err );		
       
   271 	}
       
   272 
       
   273 // --------------------------------------------------------------------------------------------------------
       
   274 // retrieves asynchronous request transactionid.
       
   275 // --------------------------------------------------------------------------------------------------------
       
   276 //
       
   277 /*TInt32 CCalendarGetList::GetTransactionID()
       
   278     {
       
   279     return(iCallBack->GetTransactionID());
       
   280     }*/
       
   281 
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // retrieves Instances based on Time Range
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CCalendarGetList::GetTimeRangeL()
       
   288     {
       
   289 
       
   290      CalCommon::TCalTimeRange range =  iFilter->TimeRange();
       
   291      if( (range.EndTime().TimeLocalL()) < (range.StartTime().TimeLocalL()) )
       
   292          User::Leave( KErrArgument );
       
   293      if ( iFilter->FilterText().Length() )
       
   294          {
       
   295          // Search and return all instances which match filter text and time range
       
   296          CCalInstanceView::TCalSearchParams searchParam( iFilter->FilterText(), CalCommon::EFoldedTextSearch );
       
   297          iSessionInfo ->InstanceView()->FindInstanceL( iInstanceList, 
       
   298                                                      iFilter->FilterType(), 
       
   299                                                      iFilter->TimeRange(), searchParam ) ;
       
   300          }
       
   301      else
       
   302          {
       
   303          // Search and return all instances which match filter type and time range
       
   304          iSessionInfo ->InstanceView()->FindInstanceL( iInstanceList, 
       
   305                                                      iFilter->FilterType(), 
       
   306                                                      iFilter->TimeRange() ) ;
       
   307          }   
       
   308     }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // retrives Entries based in GlobalUid
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 void CCalendarGetList::GetGUidL()
       
   315     {
       
   316     TPtrC8 guid(iGuid->Des());
       
   317     
       
   318     iSessionInfo ->EntryView()->FetchL( guid, iEntryList );
       
   319     }
       
   320 
       
   321 // ---------------------------------------------------------------------------
       
   322 // retrives Entries based in LocalUid
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 void CCalendarGetList::GetLocalUidL()
       
   326     {
       
   327 
       
   328    CCalEntry* entry = iSessionInfo ->EntryView()->FetchL( iLocalUid/*(*iFilter->LocalUidList())[0], iEntryList*/ );
       
   329     if( entry )
       
   330             {
       
   331             iEntryList.Append( entry );
       
   332             }
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // Call the appropriate getlist based in getlist option
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 void CCalendarGetList::StartFetchingL()
       
   340     {
       
   341     switch ( iGetListOption )
       
   342         {
       
   343         case EGetListGUid: // get guid - entries
       
   344             GetGUidL();
       
   345             break;
       
   346         
       
   347         case EGetListLocalUid: // get localid - entries
       
   348             GetLocalUidL();
       
   349              break;
       
   350                     
       
   351         case EGetListTimeRange: // get time range - instances
       
   352             GetTimeRangeL();
       
   353             break;
       
   354             
       
   355         default:
       
   356             break;
       
   357         }
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // Initialises getlist option
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CCalendarGetList::InitializeGetListOption()
       
   365     {
       
   366     //Filter having only GUids
       
   367     if ( iFilter->Filter() == EFilterGUid )
       
   368         {
       
   369         iGetListOption = EGetListGUid;
       
   370         }
       
   371     //Filter having only GUids
       
   372    else if ( iFilter->Filter() == EFilterLUid )
       
   373         {
       
   374         iGetListOption = EGetListLocalUid;
       
   375         }
       
   376  
       
   377     //Filter having time range only (No GUid/LocalUid)
       
   378     else
       
   379         {
       
   380         iGetListOption = EGetListTimeRange;
       
   381         }
       
   382     }
       
   383 // ---------------------------------------------------------------------------
       
   384 // Activates the asynchronous request
       
   385 // ---------------------------------------------------------------------------
       
   386 //
       
   387 void CCalendarGetList::ActivateRequest( TInt aReason )
       
   388 	{
       
   389 
       
   390 	SetActive();
       
   391 	
       
   392 	iStatus = KRequestPending;
       
   393 	    
       
   394 	TRequestStatus* temp = &iStatus;
       
   395 	
       
   396 	User::RequestComplete( temp, aReason );
       
   397 	
       
   398 	}
       
   399 
       
   400 
       
   401