logsui/EngineSrc/CLogsRecentReader.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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: 
       
    15 *     Recent list reader
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    22 #include <logfilterandeventconstants.hrh>
       
    23 #endif
       
    24 #include <logview.h>
       
    25 #include "CLogsRecentReader.h"
       
    26 #include "MLogsObserver.h"
       
    27 #include "MLogsEvent.h"
       
    28 #include "MLogsEventArray.h"
       
    29 #include "CLogsClearDuplicates.h"
       
    30 
       
    31 // MODULE DATA STRUCTURES
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 // ----------------------------------------------------------------------------
       
    36 // CLogsRecentReader::NewL
       
    37 // ----------------------------------------------------------------------------
       
    38 //
       
    39 CLogsRecentReader* CLogsRecentReader::NewL(
       
    40     RFs& aFsSession,
       
    41     MLogsEventArray& aEventArray,
       
    42     TLogsEventStrings& aStrings,
       
    43     TLogsModel aModelId,
       
    44     MLogsObserver* aObserver,
       
    45     CLogsEngine* aLogsEngineRef )                
       
    46     {
       
    47     CLogsRecentReader* self = new (ELeave) CLogsRecentReader
       
    48                                             (   aFsSession
       
    49                                             ,   aEventArray
       
    50                                             ,   aStrings
       
    51                                             ,   aModelId
       
    52                                             ,   aObserver
       
    53                                             ,   aLogsEngineRef
       
    54                                             );
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop();
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CLogsRecentReader::CLogsRecentReader
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 CLogsRecentReader::CLogsRecentReader(
       
    66     RFs& aFsSession,
       
    67     MLogsEventArray& aEventArray,
       
    68     TLogsEventStrings& aStrings,
       
    69     TLogsModel aModelId,
       
    70     MLogsObserver* aObserver,
       
    71     CLogsEngine* aLogsEngineRef ) :
       
    72         CLogsBaseReader(
       
    73             aFsSession,
       
    74             aEventArray,
       
    75             aStrings,
       
    76             aModelId,
       
    77             aObserver,
       
    78             aLogsEngineRef ),
       
    79         iDuplicates( EFalse )
       
    80     {
       
    81     }
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CLogsRecentReader::~CLogsRecentReader
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 CLogsRecentReader::~CLogsRecentReader()
       
    88     {    
       
    89     Cancel();
       
    90 
       
    91 /*********************************************************************************
       
    92  Changed because of EMSH-6JDFBV:
       
    93  From Jan-2006 the CLogsModel::DoDeactivate can optionally destroy missed model.
       
    94  Therefore this would wrongly clear duplicates in case UI loses foreground e.g in
       
    95  case MT missed call when missed call view is in foreground (this would cause the
       
    96  duplicate count not to increase correctely).
       
    97 
       
    98     if( iModelId == ELogsMissedModel )
       
    99         {
       
   100         TInt err;        
       
   101         TRAP( err, ClearDuplicatesL( iDuplicates, iLogViewRecent ) );   
       
   102         }
       
   103 *********************************************************************************/        
       
   104 
       
   105     delete iDuplicateView;
       
   106     delete iLogViewRecent;
       
   107     delete iDuplicateFilter;
       
   108     delete iClearDuplicates;
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------------------------------
       
   112 // CLogsRecentReader::ClearDuplicatesL
       
   113 // ----------------------------------------------------------------------------
       
   114 //
       
   115 void CLogsRecentReader::ClearDuplicatesL()
       
   116     {
       
   117     if( iLogViewRecent && iClearDuplicates )
       
   118         {
       
   119         iClearDuplicates->ClearDuplicatesL( iDuplicates, iLogViewRecent );    
       
   120         }
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------
       
   124 // CLogsRecentReader::ConstructL
       
   125 // ----------------------------------------------------------------------------
       
   126 //
       
   127 void CLogsRecentReader::ConstructL()
       
   128     {
       
   129     // iSkipClearDuplicates = EFalse; //reset skipping    
       
   130     
       
   131     BaseConstructL();    
       
   132     
       
   133     if( iModelId == ELogsMissedModel )
       
   134         {
       
   135         iClearDuplicates = CLogsClearDuplicates::NewL( iFsSession );
       
   136         }
       
   137 
       
   138     iLogViewRecent = CLogViewRecent::NewL( *iLogClientRef, *this );
       
   139     CActiveScheduler::Add( this );
       
   140     }
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // CLogsRecentReader::ActivateL
       
   144 //
       
   145 // Optimisation related to CLogsRecentReader::DeActivate (EMSH-6JDFBV).
       
   146 // ----------------------------------------------------------------------------
       
   147 //
       
   148 void CLogsRecentReader::ActivateL(  )
       
   149     {
       
   150     CLogsBaseReader::ActivateL();
       
   151         
       
   152     // iSkipClearDuplicates = aSkipClearDuplicates;
       
   153         
       
   154     if( !iLogViewRecent )
       
   155         {
       
   156         iLogViewRecent = CLogViewRecent::NewL( *iLogClientRef, *this );    
       
   157         iDirty = ETrue;
       
   158         }
       
   159     }
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // CLogsRecentReader::DeActivate
       
   163 //
       
   164 // Optimisation for reducing Logs resource consumption when a MT call is received and 
       
   165 // in the same time processing power is needed for ring tune retrieval etc. This function
       
   166 // is not necessary if calling CLogsRecentReader::Stop() provides sufficient result (EMSH-6JDFBV).
       
   167 // void CLogsRecentReader::DeActivate( TBool aSkipClearDuplicates )
       
   168 // ----------------------------------------------------------------------------
       
   169 //
       
   170 void CLogsRecentReader::DeActivate( )
       
   171     {
       
   172     CLogsBaseReader::DeActivate( );
       
   173         
       
   174     // iSkipClearDuplicates = aSkipClearDuplicates;
       
   175     
       
   176     Cancel();   //Calls syncronously DoCancel() below
       
   177 
       
   178     /* optimisation attempt for EMSH-6JDFBV *
       
   179         if( iClearDuplicates && !iSkipClearDuplicates )
       
   180             {
       
   181             delete iClearDuplicates; //We've already called cancel for iClearDuplicates in DoCancel()
       
   182             iClearDuplicates = NULL;
       
   183             }
       
   184     */
       
   185 
       
   186     delete iLogViewRecent;
       
   187     iLogViewRecent = NULL;
       
   188     iDirty = ETrue;
       
   189     
       
   190     //Reset event array, because otherwise navigating in UI between recent views takes too long to 
       
   191     //read last status from database. That may cause user to use wrong event line in view.
       
   192     //If performance is good enough, the below is not needed.    
       
   193     iEventArray.Reset(); 
       
   194     
       
   195     TInt err;        
       
   196     TRAP( err, iObserver->StateChangedL( this ) );
       
   197     }
       
   198 
       
   199 // ----------------------------------------------------------------------------
       
   200 // CLogsRecentReader::DoCancel
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 void CLogsRecentReader::DoCancel()
       
   204     {
       
   205     if( iLogViewRecent )
       
   206         {
       
   207         iLogViewRecent->Cancel();
       
   208         }
       
   209     
       
   210     if( iDuplicateView )
       
   211         {
       
   212         iDuplicateView->Cancel();
       
   213         }
       
   214         
       
   215     /* optimisation attempt for EMSH-6JDFBV *
       
   216     if( iClearDuplicates && iSkipClearDuplicates )
       
   217         {
       
   218         iClearDuplicates->Cancel(); //calls cancel for it's own view + for iLogClient
       
   219         }
       
   220     */
       
   221 
       
   222     CLogsBaseReader::DoCancel();    //calls iLogClient->Cancel()        
       
   223     }
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // CLogsRecentReader::DoNextL
       
   227 //
       
   228 // Called from CLogsBaseReader::NextL
       
   229 // ----------------------------------------------------------------------------
       
   230 //
       
   231 TBool CLogsRecentReader::DoNextL()
       
   232     {
       
   233     TBool rc( EFalse );
       
   234     
       
   235     switch( iPhase )
       
   236         {
       
   237         case ERead:
       
   238             rc = iLogViewRecent->NextL( iStatus );
       
   239             break;
       
   240 
       
   241         case EDuplicate:    //BaseReader sets this phase if running missed model 
       
   242             if( !iDuplicateView )
       
   243                 {
       
   244                 iDuplicateView = CLogViewDuplicate::NewL( *iLogClientRef );
       
   245                 }
       
   246                 
       
   247             if( !iDuplicateFilter)
       
   248                 {
       
   249                 iDuplicateFilter = CLogFilter::NewL();
       
   250                 iDuplicateFilter->SetFlags( KLogEventRead );
       
   251                 iDuplicateFilter->SetNullFields( ELogFlagsField );
       
   252                 }
       
   253 
       
   254             //DuplicatesL: refreshes duplicate event view with the duplicates of the current 
       
   255             //event in the recent event list view. Is an asynchronous request.
       
   256             //rc = False, if there are no events in the view. 
       
   257             rc = iLogViewRecent->DuplicatesL( *iDuplicateView, 
       
   258                                     *iDuplicateFilter, iStatus ); 
       
   259 
       
   260             if( ! rc )
       
   261                 {
       
   262                 // no duplicates in this duplicate view, go to next one
       
   263                 ++iIndex;
       
   264                 iPhase = ERead;
       
   265                 rc = DoNextL(); // recursion
       
   266                 } 
       
   267             else
       
   268                 {
       
   269                 iDuplicates = ETrue;
       
   270                 }
       
   271             break;
       
   272 
       
   273         default:
       
   274             break;
       
   275         } 
       
   276 
       
   277     return rc;
       
   278     }
       
   279 
       
   280 // ----------------------------------------------------------------------------
       
   281 // CLogsRecentReader::StartL
       
   282 // ----------------------------------------------------------------------------
       
   283 //
       
   284 void CLogsRecentReader::StartL()
       
   285     {
       
   286     //Starting may be called in total refresh situations even if we're 
       
   287     //are not active at moment. In that case this model (recent, missed, or dialled) 
       
   288     //is e.g. in the background and we don't refresh it yet (relates to EMSH-6JDFBV)
       
   289     if( !iLogViewRecent )
       
   290         {
       
   291         return;
       
   292         }
       
   293     
       
   294     iIndex = 0;
       
   295     
       
   296     //The cancel() below seems consume quite much time on hw, so we don't call unless necessary
       
   297     if( IsActive() )
       
   298         {
       
   299         Cancel();
       
   300         }
       
   301     
       
   302         
       
   303     iDirty = EFalse;
       
   304     iInterrupted = EFalse;
       
   305     TBool rc = EFalse;
       
   306     iState = EStateInitializing; //This informs observers that e.g. a complete re-read of recent events is about to begin
       
   307                                  //so that they can e.g. change their view focus settings accordingly
       
   308                                  // (e.g. CLogsRecentListView::StateChangedL )
       
   309 
       
   310     // FIXME: Following statement takes more than 100 ms seconds to execute. The trapd statement is 
       
   311     // known to be expensive but it should not take that long. Seems to be a Symbian caused performance 
       
   312     // bottleneck cause the asynch request should not take that long to return. 
       
   313     TRAPD( err, rc = iLogViewRecent->SetRecentListL( ( TInt8 )iModelId, iStatus ) );    //asynch request
       
   314     if( err == KErrAccessDenied )
       
   315         {
       
   316         iDirty = ETrue;
       
   317         return;
       
   318         }
       
   319     User::LeaveIfError(err);
       
   320 
       
   321     if( rc )
       
   322         {
       
   323         iPhase = ERead;
       
   324         SetActive();
       
   325         }
       
   326     else 
       
   327         {
       
   328         Cancel();
       
   329         if( iObserver )
       
   330             {
       
   331             iEventArray.Reset();
       
   332             iPhase = EDone;
       
   333             iState = EStateFinished;
       
   334             iObserver->StateChangedL( this );
       
   335             }
       
   336         }
       
   337     }
       
   338 
       
   339 // ----------------------------------------------------------------------------
       
   340 // CLogsRecentReader::DuplicateCountL
       
   341 // ----------------------------------------------------------------------------
       
   342 //
       
   343 TInt CLogsRecentReader::DuplicateCountL() const
       
   344     {
       
   345     if( !iDuplicateView )
       
   346         {
       
   347         return 0;
       
   348         }
       
   349         
       
   350     return iDuplicateView->CountL();
       
   351     }
       
   352 
       
   353 // ----------------------------------------------------------------------------
       
   354 // CLogsRecentReader::ReadingFinishedL
       
   355 // ----------------------------------------------------------------------------
       
   356 //
       
   357 void CLogsRecentReader::ReadingFinishedL()
       
   358     {
       
   359     CLogsBaseReader::ReadingFinishedL();
       
   360     delete iDuplicateView;
       
   361     iDuplicateView = NULL;
       
   362     }
       
   363 
       
   364 // ----------------------------------------------------------------------------
       
   365 // CLogsRecentReader::Stop
       
   366 // ----------------------------------------------------------------------------
       
   367 //
       
   368 void CLogsRecentReader::Stop()
       
   369     {
       
   370     Cancel();   //Calls syncronously CLogsRecentReader::DoCancel(). Takes care of calling 
       
   371                 // also Cancel() for iClearDuplicates
       
   372     }
       
   373 
       
   374 // ----------------------------------------------------------------------------
       
   375 // CLogsRecentReader::ViewCountL
       
   376 // ----------------------------------------------------------------------------
       
   377 //
       
   378 TInt CLogsRecentReader::ViewCountL() const
       
   379     {
       
   380     return iLogViewRecent->CountL();
       
   381     }
       
   382 
       
   383 // ----------------------------------------------------------------------------
       
   384 // CLogsRecentReader::Event
       
   385 // ----------------------------------------------------------------------------
       
   386 //
       
   387 CLogEvent& CLogsRecentReader::Event() const
       
   388     {
       
   389     //The RVCT compiler provides warnings "type qualifier on return type is meaningless"
       
   390     //for functions that return const values. In order to avoid these numerous warnings and 
       
   391     //const cascading, the CLogEvent is const_casted here.
       
   392     return const_cast<CLogEvent&>( iLogViewRecent->Event() );
       
   393     }
       
   394 
       
   395 // ----------------------------------------------------------------------------
       
   396 // CLogsRecentReader::ConstructEventL
       
   397 // ----------------------------------------------------------------------------
       
   398 //
       
   399 void CLogsRecentReader::ConstructEventL
       
   400     (   MLogsEvent& aDest
       
   401     ,   const CLogEvent& aSource
       
   402     )
       
   403     {
       
   404     BaseConstructEventL( aDest, aSource );
       
   405     }
       
   406 
       
   407 // ----------------------------------------------------------------------------
       
   408 // CLogsRecentReader::ConfigureL
       
   409 // ----------------------------------------------------------------------------
       
   410 //
       
   411 void CLogsRecentReader::ConfigureL( const MLogsReaderConfig* /*aConfig*/ )
       
   412     {
       
   413     User::Leave( KErrNotSupported );
       
   414     }
       
   415 
       
   416