logsui/EngineSrc/CLogsClearNewMissed.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 *     Class for setting a missed calls event and its duplicates read. This is needed only for 
       
    16 *     clearing the new missed icon and duplicate counters for one missed call event if a call or 
       
    17 *     message is initiated. 
       
    18 *     
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include <logcli.h>
       
    25 #include <logview.h>
       
    26 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    27 #include <logwrap.hrh>
       
    28 #else
       
    29 #include <logwrap.hrh>
       
    30 #include <logfilterandeventconstants.hrh>
       
    31 #endif
       
    32 #include "CLogsClearNewMissed.h"
       
    33 #include "MLogsObserver.h"
       
    34 #include "LogsUID.h"
       
    35 #include "LogsEngConsts.h"
       
    36 
       
    37 
       
    38 
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // CLogsClearNewMissed::NewL
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 CLogsClearNewMissed* CLogsClearNewMissed::NewL( 
       
    45     RFs& aFsSession)
       
    46     {
       
    47     CLogsClearNewMissed* self = new (ELeave) CLogsClearNewMissed( aFsSession );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop();
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CLogsClearNewMissed::CLogsClearNewMissed
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 CLogsClearNewMissed::CLogsClearNewMissed( 
       
    59     RFs& aFsSession ) :
       
    60         CActive( EPriorityStandard ),
       
    61         iFsSession( aFsSession ),
       
    62         iPhase( EUnInitilized )
       
    63     {
       
    64     }
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // CLogsClearNewMissed::ConstructL
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 void CLogsClearNewMissed::ConstructL()
       
    71     {
       
    72     iLogClient = CLogClient::NewL( iFsSession );
       
    73     iPhase = EUnInitilized;
       
    74    
       
    75     CActiveScheduler::Add( this ); 
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // CLogsClearNewMissed::~CLogsClearNewMissed
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 CLogsClearNewMissed::~CLogsClearNewMissed()
       
    83     {
       
    84     Cancel(); 
       
    85     delete iLogViewRecent;
       
    86     delete iRecentFilter;
       
    87     delete iLogViewDuplicates;
       
    88     delete iDuplicateFilter;
       
    89     delete iLogClient;    
       
    90     delete iLogEvent;
       
    91     }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CLogsClearNewMissed::DoCancel
       
    95 // ----------------------------------------------------------------------------
       
    96 //
       
    97 void CLogsClearNewMissed::DoCancel()
       
    98     {    
       
    99     if (iLogViewDuplicates)
       
   100         {
       
   101         iLogViewDuplicates->Cancel();
       
   102         }
       
   103         
       
   104     if (iLogViewRecent)
       
   105         {
       
   106         iLogViewRecent->Cancel();
       
   107         }
       
   108     
       
   109     if( iLogClient )
       
   110         {
       
   111         iLogClient->Cancel();
       
   112         }
       
   113     }
       
   114 
       
   115 // ----------------------------------------------------------------------------
       
   116 // CLogsClearNewMissed::SetNewMissedCallRead
       
   117 // ----------------------------------------------------------------------------
       
   118 //
       
   119 void CLogsClearNewMissed::SetNewMissedCallRead(TLogId aLogId, TInt aDuplicates) 
       
   120     {
       
   121     iDuplicates = aDuplicates;
       
   122     
       
   123     // First we must read the event from the log db 
       
   124     if ( !IsActive() && (iPhase == EFinished || iPhase == EUnInitilized ) )
       
   125         {
       
   126         TRAPD(err, GetEventL(aLogId));
       
   127         if (err)
       
   128             {
       
   129             // If there was a leave, just let this fail. Nothing to do.
       
   130             }
       
   131         }
       
   132     else
       
   133         {
       
   134         // If still active, we don't do anything. The UI should prevent this from being possible
       
   135         }
       
   136     }
       
   137 
       
   138 // ----------------------------------------------------------------------------
       
   139 // CLogsClearNewMissed::GetEventL
       
   140 // ----------------------------------------------------------------------------
       
   141 //    
       
   142 void CLogsClearNewMissed::GetEventL(TLogId aLogId) 
       
   143     {
       
   144     delete iLogEvent;
       
   145     iLogEvent = NULL;
       
   146     iLogEvent = CLogEvent::NewL();
       
   147     
       
   148     // When this asynchronous call finishes, the log event will contain all the event data
       
   149     // corresponding to the event id. 
       
   150     iLogEvent->SetId(aLogId);
       
   151     iLogClient->GetEvent( *iLogEvent, iStatus );
       
   152       
       
   153     iPhase = EGetEvent;
       
   154     SetActive();  
       
   155     }
       
   156 
       
   157 // ----------------------------------------------------------------------------
       
   158 // CLogsClearNewMissed::RunL
       
   159 // ----------------------------------------------------------------------------
       
   160 //
       
   161 void CLogsClearNewMissed::RunL()
       
   162     {
       
   163     if (iStatus != KErrNone)
       
   164         {
       
   165         iPhase = EFinished;
       
   166         }
       
   167     else    
       
   168         {
       
   169         switch(iPhase)
       
   170             {
       
   171             // 1.st phase: event data fetched from db. 
       
   172             case EGetEvent: 
       
   173                 {      
       
   174                 // If event has duplicates continue to setting the CLogViewRecent if possible
       
   175                 if ( TrySetRecentViewL() )
       
   176                     {
       
   177                     iPhase = ESetRecentView;
       
   178                     SetActive();
       
   179                     } 
       
   180                 // Otherwise just set this event read. 
       
   181                 else
       
   182                     {  
       
   183                     iLogEvent->SetFlags( iLogEvent->Flags() | KLogEventRead );                                  
       
   184                     iLogClient->ChangeEvent( *iLogEvent, iStatus );
       
   185                     
       
   186                     iPhase = EChangeEvent;
       
   187                     SetActive();  
       
   188                     }                
       
   189                 break;
       
   190                 }
       
   191            
       
   192             case EChangeEvent: // If event has duplicates this state is skipped.    
       
   193                 {
       
   194                 // Nothing to do anymore
       
   195                 iPhase = EFinished;
       
   196                 break;
       
   197                 }
       
   198                    
       
   199             // Recent view set, set the duplicate view 
       
   200             case ESetRecentView:       
       
   201                 {              
       
   202                 if ( TrySetDuplicatesViewL() )
       
   203                     {
       
   204                     iPhase = ESetDuplicatesView;
       
   205                     SetActive(); 
       
   206                     }
       
   207                 else
       
   208                     {
       
   209                     // if there are no duplicates after all, just set the KLogEventRead flag 
       
   210                     // for the recent view
       
   211                     SetReadFlagsL();
       
   212                     iPhase = EFinished;
       
   213                     }
       
   214                 break;
       
   215                 }
       
   216                 
       
   217             // Duplicate view set, set KLogEventRead flag for the views
       
   218             case ESetDuplicatesView: 
       
   219                 {    
       
   220                 SetReadFlagsL();
       
   221                 iPhase = EFinished;
       
   222                 break;
       
   223                 }
       
   224  
       
   225             default:
       
   226                 {
       
   227                 break;
       
   228                 }
       
   229             }    
       
   230         }
       
   231     }
       
   232 
       
   233 // ----------------------------------------------------------------------------
       
   234 // CLogsClearNewMissed::TrySetDuplicatesViewL
       
   235 // ----------------------------------------------------------------------------
       
   236 //
       
   237 TBool CLogsClearNewMissed::TrySetDuplicatesViewL() 
       
   238     {
       
   239     if( !iLogViewDuplicates )
       
   240         {
       
   241         iLogViewDuplicates = CLogViewDuplicate::NewL( *iLogClient );
       
   242         }
       
   243     
       
   244     // Duplicates filter is always the same, no need to recreate
       
   245     // or "reset" after it has once been set
       
   246     if( !iDuplicateFilter)
       
   247         {
       
   248         iDuplicateFilter = CLogFilter::NewL();
       
   249         iDuplicateFilter->SetFlags( KLogEventRead );
       
   250         iDuplicateFilter->SetNullFields( ELogFlagsField );    
       
   251         }
       
   252              
       
   253     //DuplicatesL refreshes duplicate event view with the duplicates of the current 
       
   254     //event in the recent event list view. Is an asynchronous request.
       
   255     //rc = False, if there are no events in the view. 
       
   256     TBool rc;
       
   257     rc = iLogViewRecent->DuplicatesL( *iLogViewDuplicates, 
       
   258                                       *iDuplicateFilter, iStatus );                   
       
   259     if (rc)
       
   260         {
       
   261         // Duplicates view set and contains events
       
   262         return ETrue;
       
   263         }
       
   264     else 
       
   265         {
       
   266         // If no duplicates after all revert back to recent view.
       
   267         return EFalse;
       
   268         }
       
   269     }
       
   270               
       
   271 // ----------------------------------------------------------------------------
       
   272 // CLogsClearNewMissed::TrySetRecentViewL
       
   273 // ----------------------------------------------------------------------------
       
   274 //
       
   275 TBool CLogsClearNewMissed::TrySetRecentViewL()
       
   276     {
       
   277     // If there are no duplicates or event has neither Number or Remoteparty
       
   278     // set, then stop now and revert to just setting the latest event read
       
   279     if ( iDuplicates == 0 ||
       
   280          ( iLogEvent->Number().Length() == 0 &&
       
   281            iLogEvent->RemoteParty().Length() == 0 )   )
       
   282         {            
       
   283         return EFalse;
       
   284         }
       
   285     
       
   286     // Otherwise continue to settin the recent view, which is needed to get the duplicates view
       
   287     // of the recent event.
       
   288     //
       
   289     if( !iLogViewRecent )
       
   290         {
       
   291         iLogViewRecent = CLogViewRecent::NewL( *iLogClient );
       
   292         }
       
   293     //
       
   294     SetRecentFilterL();
       
   295     
       
   296     
       
   297     TInt rc;
       
   298     rc = iLogViewRecent->SetRecentListL( ( TInt8 )ELogsMissedModel, *iRecentFilter, iStatus );    //asynch request
       
   299 
       
   300     if( rc == 1 )
       
   301         {
       
   302         // If just one event in the list, like it should, continue to getting the duplicates view.
       
   303         return ETrue;
       
   304         }
       
   305     else  
       
   306         {
       
   307         // No events in the view after all or multiple events found, return EFalse
       
   308         // will revert to just setting the latest event read
       
   309         return EFalse;
       
   310         }
       
   311       
       
   312     }
       
   313 
       
   314 // ----------------------------------------------------------------------------
       
   315 // CLogsClearNewMissed::SetRecentFilterL   
       
   316 // ----------------------------------------------------------------------------
       
   317 //
       
   318 void CLogsClearNewMissed::SetRecentFilterL()
       
   319     {
       
   320     // Always start fresh with the filter, so delete the old one and create new.
       
   321     delete iRecentFilter;
       
   322     iRecentFilter = NULL;
       
   323     iRecentFilter = CLogFilter::NewL();
       
   324     
       
   325     if (iLogEvent->Number().Length() != 0)
       
   326         {
       
   327         iRecentFilter->SetNumber(iLogEvent->Number()); 
       
   328         }
       
   329     
       
   330     if (iLogEvent->RemoteParty().Length() != 0 )
       
   331         {   
       
   332         iRecentFilter->SetRemoteParty(iLogEvent->RemoteParty()); 
       
   333         }
       
   334     
       
   335     }
       
   336 
       
   337  
       
   338 // ----------------------------------------------------------------------------
       
   339 // CLogsClearNewMissed::SetReadFlagsL
       
   340 // ----------------------------------------------------------------------------
       
   341 //
       
   342 void CLogsClearNewMissed::SetReadFlagsL()
       
   343     {
       
   344     iLogViewRecent->SetFlagsL( iLogEvent->Flags() | KLogEventRead );
       
   345     
       
   346     // By setting the duplicates view to read, the duplicates counter is also reseted
       
   347     // incase there will be new missed calls from the same number after SetReadFlagsL
       
   348     // (and CLogsClearDuplicates has not been run).
       
   349     if (iLogViewDuplicates && iPhase == ESetDuplicatesView)
       
   350         { 
       
   351         iLogViewDuplicates->SetFlagsL( iLogEvent->Flags() | KLogEventRead ); 
       
   352         }
       
   353     }
       
   354             
       
   355 // ----------------------------------------------------------------------------
       
   356 // CLogsClearNewMissed::RunError
       
   357 // ----------------------------------------------------------------------------
       
   358 //
       
   359 TInt CLogsClearNewMissed::RunError(TInt aError)
       
   360 	{
       
   361 	if( aError == KErrAccessDenied )
       
   362 		{
       
   363 		return KErrNone;
       
   364 		}
       
   365 	else
       
   366 		{
       
   367 		return aError;
       
   368 		}
       
   369 	}