logsui/logsengine/logssymbianos/src/logsremove.cpp
changeset 0 4a5361db8937
child 9 68f3171a5819
equal deleted inserted replaced
-1:000000000000 0:4a5361db8937
       
     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 "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 //USER
       
    19 #include "logsremove.h"
       
    20 #include "logsmodel.h"
       
    21 #include "logslogger.h"
       
    22 #include "logsremoveobserver.h"
       
    23 #include <logcli.h>
       
    24 #include <f32file.h>
       
    25 #include <logview.h>
       
    26 //SYSTEM
       
    27 
       
    28 // CONSTANTS
       
    29 _LIT( KMaxLogsTime, "99991130:235959.999999");
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 LogsRemove::LogsRemove( LogsRemoveObserver& observer, bool readingAllEvents )
       
    36 : CActive(EPriorityStandard),
       
    37   mObserver(observer),
       
    38   mReadingAllEvents(readingAllEvents),
       
    39   mLogClient(0),
       
    40   mRecentView(0)
       
    41 {
       
    42 	CActiveScheduler::Add( this );
       
    43     mFsSession = new RFs();
       
    44 }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // LogsRemove::~LogsRemove
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 LogsRemove::~LogsRemove()
       
    51 {
       
    52     LOGS_QDEBUG( "logs [ENG] <-> LogsRemove::~LogsRemove()" )
       
    53     Cancel();
       
    54     delete mRecentView;
       
    55     delete mLogClient;
       
    56     if ( mFsSession ){
       
    57         mFsSession->Close();
       
    58     }
       
    59     delete mFsSession;
       
    60 }
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // LogsRemove::RunL
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 void LogsRemove::RunL()
       
    67 {
       
    68     LOGS_QDEBUG( "logs [ENG] -> LogsRemove::RunL()->" )
       
    69    if (iStatus.Int() == KErrNone){
       
    70     	LOGS_QDEBUG( "logs [ENG] -> LogsRemove::RunL() KErrNone" )
       
    71     	if ( !DeleteNextEvent() ){
       
    72             mObserver.removeCompleted();
       
    73     	}
       
    74     }
       
    75     else {
       
    76     	User::Leave( iStatus.Int() );
       
    77     	LOGS_QDEBUG( "logs [ENG] -> LogsRemove::RunL() !KErrNone" )
       
    78     }
       
    79     LOGS_QDEBUG( "logs [ENG] <- LogsRemove::RunL()<-" )
       
    80 }
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // LogsRemove::DoCancel
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 void LogsRemove::DoCancel()
       
    87 {
       
    88 	if ( mLogClient ){
       
    89         mLogClient->Cancel();
       
    90     }
       
    91 }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // LogsRemove::RunError
       
    95 // ----------------------------------------------------------------------------
       
    96 //
       
    97 TInt LogsRemove::RunError(TInt aError)
       
    98 {
       
    99 	mObserver.logsRemoveErrorOccured(aError);
       
   100 	return KErrNone;	
       
   101 }
       
   102 
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // LogsRemove::init
       
   106 // ----------------------------------------------------------------------------
       
   107 //
       
   108 int LogsRemove::init()
       
   109 {
       
   110     LOGS_QDEBUG( "logs [ENG] -> LogsRemove::init()" )    
       
   111     TRAPD( err, initL() );
       
   112     LOGS_QDEBUG_2( "logs [ENG] <- LogsRemove::init(), err:", err )    
       
   113     return err;
       
   114 }
       
   115 
       
   116 
       
   117 // ----------------------------------------------------------------------------
       
   118 // LogsRemove::clearList
       
   119 // ----------------------------------------------------------------------------
       
   120 //
       
   121 bool LogsRemove::clearList(LogsModel::ClearType cleartype)
       
   122 {
       
   123     LOGS_QDEBUG( "logs [ENG] <- LogsRemove::clearList->" )
       
   124     if ( init() != KErrNone ) {
       
   125         return false;
       
   126     }
       
   127     bool clearingStarted(false);
       
   128     TTime time( KMaxLogsTime );
       
   129     if ( !IsActive() ){
       
   130         if (cleartype == LogsModel::TypeLogsClearAll){
       
   131             mLogClient->ClearLog( time, iStatus );
       
   132         }
       
   133         else{
       
   134             mLogClient->ClearLog( cleartype, iStatus );
       
   135         }
       
   136         SetActive();  
       
   137         clearingStarted = true;
       
   138     } else {
       
   139     }
       
   140     LOGS_QDEBUG_2( "logs [ENG] <- LogsRemove::clearList, started", clearingStarted )
       
   141     return clearingStarted;
       
   142 }
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // LogsRemove::initL
       
   146 // ----------------------------------------------------------------------------
       
   147 //
       
   148 void LogsRemove::initL()
       
   149 {
       
   150     if ( mLogClient ){
       
   151         // Already initialized
       
   152         return;
       
   153     }  
       
   154     User::LeaveIfError( mFsSession->Connect() );
       
   155     mLogClient = CLogClient::NewL( *mFsSession );
       
   156 }
       
   157 
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // LogsRemove::clearEvents
       
   161 // ----------------------------------------------------------------------------
       
   162 //
       
   163 int LogsRemove::clearEvents(const QList<int>& eventIds, bool& async)
       
   164 {
       
   165     TRAPD( err, clearEventsL(eventIds, async) );
       
   166     return err;
       
   167 }
       
   168     
       
   169 // ----------------------------------------------------------------------------
       
   170 // LogsRemove::clearEventsL
       
   171 // ----------------------------------------------------------------------------
       
   172 //
       
   173 void LogsRemove::clearEventsL(const QList<int>& eventIds, bool& async)
       
   174 {
       
   175     LOGS_QDEBUG( "logs [ENG] -> LogsRemove::clearEventL()")
       
   176 
       
   177     async = false;
       
   178     
       
   179     initL();
       
   180     
       
   181     if ( mReadingAllEvents ){
       
   182         // When all events are read, recent view cannot be used for 
       
   183         // event removal.
       
   184         Cancel();
       
   185         mRemovedEvents = eventIds;
       
   186         async = DeleteNextEvent();
       
   187     } else {
       
   188         if ( !mRecentView ) {
       
   189             mRecentView = CLogViewRecent::NewL( *mLogClient );
       
   190         }
       
   191         foreach( int currId, eventIds ){
       
   192             LOGS_QDEBUG_2( "logs [ENG]  Removing, currid: ", currId )
       
   193             mRecentView->RemoveL( currId );
       
   194         }
       
   195         delete mRecentView;
       
   196         mRecentView = NULL;
       
   197     }
       
   198     
       
   199     LOGS_QDEBUG_2( "logs [ENG] <- LogsRemove::clearEventL(): async", async ) 
       
   200 }
       
   201 
       
   202 // ----------------------------------------------------------------------------
       
   203 // LogsRemove::DeleteNextEvent
       
   204 // ----------------------------------------------------------------------------
       
   205 //
       
   206 bool LogsRemove::DeleteNextEvent()
       
   207 {
       
   208     bool deleting(false);
       
   209     if ( !mRemovedEvents.isEmpty() ){
       
   210         int currId = mRemovedEvents.takeFirst();
       
   211         LOGS_QDEBUG_2( "logs [ENG]  LogsRemove::DeleteNextEvent, id: ", currId )
       
   212         mLogClient->DeleteEvent( currId, iStatus );
       
   213         SetActive();
       
   214         deleting = true;
       
   215     }
       
   216     return deleting;  
       
   217 }
       
   218 
       
   219 // End of file
       
   220