logsui/EngineSrc/CLogsClearLog.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 log clearing
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <logcli.h>
       
    22 #include <logview.h>
       
    23 #include <sysutil.h>
       
    24 
       
    25 #include "CLogsClearLog.h"
       
    26 #include "MLogsObserver.h"
       
    27 #include "LogsUID.h"
       
    28 
       
    29 #include "LogsDebug.h"
       
    30 #include "LogsTraces.h"
       
    31 
       
    32 // CONSTANTS
       
    33 _LIT( KMaxTime, "99991130:235959.999999");
       
    34 const TInt KBytesToRequest ( 64 * 1024 );
       
    35 
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // CLogsClearLog::NewL
       
    39 // ----------------------------------------------------------------------------
       
    40 //
       
    41 CLogsClearLog* CLogsClearLog::NewL( 
       
    42     RFs& aFsSession,
       
    43     MLogsObserver* aObserver )
       
    44     {
       
    45     TRACE_ENTRY_POINT;
       
    46     
       
    47     CLogsClearLog* self = new (ELeave) CLogsClearLog( aFsSession, aObserver );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop();
       
    51     
       
    52     TRACE_EXIT_POINT;
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // CLogsClearLog::CLogsClearLog
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 CLogsClearLog::CLogsClearLog( 
       
    61     RFs& aFsSession, MLogsObserver* aObserver ) :
       
    62         CActive( EPriorityStandard ),
       
    63         iFsSession( aFsSession ),
       
    64         iObserver( aObserver ),
       
    65         iState( EStateUndefined )
       
    66     {
       
    67     TRACE_ENTRY_POINT;
       
    68     TRACE_EXIT_POINT;
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CLogsClearLog::ConstructL
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 void CLogsClearLog::ConstructL()
       
    76     {
       
    77     TRACE_ENTRY_POINT;
       
    78     iLogClient = CLogClient::NewL( iFsSession );
       
    79     CActiveScheduler::Add( this );
       
    80     TRACE_EXIT_POINT; 
       
    81     }
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CLogsClearLog::~CLogsClearLog
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 CLogsClearLog::~CLogsClearLog()
       
    88     {
       
    89     TRACE_ENTRY_POINT;
       
    90     Cancel();     
       
    91     delete iViewRecent;
       
    92     delete iLogClient;
       
    93     TRACE_EXIT_POINT;
       
    94     }
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // CLogsClearLog::SetObserver
       
    98 // ----------------------------------------------------------------------------
       
    99 //
       
   100 void CLogsClearLog::SetObserver( MLogsObserver* aObserver )
       
   101     {
       
   102     TRACE_ENTRY_POINT;
       
   103     iObserver = aObserver;
       
   104     TRACE_EXIT_POINT;
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // CLogsClearLog::DoCancel
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 void CLogsClearLog::DoCancel()
       
   112     { 
       
   113     TRACE_ENTRY_POINT;
       
   114     
       
   115     if( iViewRecent )
       
   116         {
       
   117         iViewRecent->Cancel();
       
   118         }
       
   119         
       
   120     if( iLogClient )
       
   121         {
       
   122         iLogClient->Cancel();
       
   123         }
       
   124         
       
   125     TRACE_EXIT_POINT;
       
   126     }
       
   127 
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 // CLogsClearLog::State
       
   131 // ----------------------------------------------------------------------------
       
   132 //
       
   133 TLogsState CLogsClearLog::State() const
       
   134     {
       
   135     TRACE_ENTRY_POINT;
       
   136     TRACE_EXIT_POINT;
       
   137     return iState;
       
   138     }
       
   139 
       
   140 
       
   141 // ----------------------------------------------------------------------------
       
   142 // CLogsClearLog::ClearModelL
       
   143 // ----------------------------------------------------------------------------
       
   144 //
       
   145 void CLogsClearLog::ClearModelL( const TLogsModel aModel )
       
   146     {
       
   147     TRACE_ENTRY_POINT;
       
   148     TTime time( KMaxTime );
       
   149 
       
   150     iPhase = EClearLog;
       
   151 
       
   152     if( !IsActive() )
       
   153         { 
       
   154         // If disk space below critical, we will leave here and a global error note is
       
   155         // to be shown
       
   156         if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, KBytesToRequest ) )
       
   157             {       
       
   158             LOGS_DEBUG_PRINT(LOGS_DEBUG_STRING
       
   159                 ( "CLogsClearLog::ClearModelL - FFSSpaceBelowCriticalLevelL" )); 
       
   160             // don't show any own notes here 
       
   161             User::Leave( KErrDiskFull );
       
   162             }   
       
   163 
       
   164         
       
   165         switch( aModel )
       
   166             {
       
   167             case ELogsMainModel:
       
   168                 iLogClient->ClearLog( time, iStatus );
       
   169                 break;
       
   170 
       
   171             case ELogsAllRecent: // fall through
       
   172             case ELogsReceivedModel:
       
   173             case ELogsDialledModel:
       
   174             case ELogsMissedModel:
       
   175             default:                
       
   176                 iLogClient->ClearLog( aModel, iStatus );
       
   177                 break;
       
   178             }
       
   179             
       
   180         SetActive();
       
   181         }
       
   182         
       
   183     TRACE_EXIT_POINT;    
       
   184     }
       
   185 
       
   186 // ----------------------------------------------------------------------------
       
   187 // CLogsClearLog::DeleteEventL
       
   188 // ----------------------------------------------------------------------------
       
   189 //
       
   190 void CLogsClearLog::DeleteEventL( TLogId aId )
       
   191     {
       
   192     TRACE_ENTRY_POINT;
       
   193     iPhase = EClearEvent;
       
   194 
       
   195     if( iViewRecent )
       
   196         {
       
   197         delete iViewRecent;
       
   198         iViewRecent = NULL;
       
   199         }
       
   200         
       
   201     iViewRecent = CLogViewRecent::NewL( *iLogClient );
       
   202     iViewRecent->RemoveL( aId );
       
   203     iState = EStateClearLogFinished;
       
   204     
       
   205     if( iObserver )
       
   206         {
       
   207         iObserver->StateChangedL( this );
       
   208         }
       
   209         
       
   210     TRACE_EXIT_POINT;    
       
   211     }
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // CLogsClearLog::RunL
       
   215 // ----------------------------------------------------------------------------
       
   216 //
       
   217 void CLogsClearLog::RunL()
       
   218     {
       
   219     TRACE_ENTRY_POINT;  
       
   220         
       
   221     iState = EStateClearLogFinished;
       
   222     
       
   223     if( iObserver )
       
   224         {
       
   225         iObserver->StateChangedL( this );
       
   226         }
       
   227         
       
   228     TRACE_EXIT_POINT;     
       
   229     }
       
   230 
       
   231 // ----------------------------------------------------------------------------
       
   232 // CLogsClearLog::RunError
       
   233 // ----------------------------------------------------------------------------
       
   234 //
       
   235 TInt CLogsClearLog::RunError(TInt aError)
       
   236 	{
       
   237 	TRACE_ENTRY_POINT;
       
   238 	TInt ret;
       
   239 	
       
   240 	if( aError == KErrAccessDenied )
       
   241 		{
       
   242 		ret = KErrNone;
       
   243 		}
       
   244 	else
       
   245 		{
       
   246 		ret = aError;
       
   247 		}
       
   248 		
       
   249 	TRACE_EXIT_POINT; 
       
   250 	return ret;	
       
   251 	}