logsui/logsengine/logssymbianos/src/logsremovestates.cpp
changeset 9 68f3171a5819
child 15 76d2cf7a585e
equal deleted inserted replaced
8:6c9acdc6adc0 9:68f3171a5819
       
     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 // INCLUDE FILES
       
    19 #include "logsremovestates.h"
       
    20 #include "logsstatebasecontext.h"
       
    21 #include "logsremovestatecontext.h"
       
    22 #include "logslogger.h"
       
    23 #include "logsremoveobserver.h"
       
    24 #include "logsmodel.h"
       
    25 #include <logview.h>
       
    26 #include <logwraplimits.h>
       
    27 
       
    28 _LIT( KMaxLogsTime, "99991130:235959.999999");
       
    29     
       
    30 // ----------------------------------------------------------------------------
       
    31 // LogsRemoveStateBase
       
    32 // ----------------------------------------------------------------------------
       
    33 //
       
    34 LogsRemoveStateBase::LogsRemoveStateBase(
       
    35     LogsStateBaseContext& context, LogsRemoveStateContext& removeContext) : 
       
    36     LogsStateBase(context), mContext(removeContext)
       
    37 {
       
    38 
       
    39 }
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // LogsRemoveStateClearAll
       
    43 // ----------------------------------------------------------------------------
       
    44 //
       
    45 bool LogsRemoveStateClearAll::enterL()
       
    46 {
       
    47     TTime time( KMaxLogsTime );
       
    48     if (mContext.clearType() == LogsModel::TypeLogsClearAll){
       
    49         mBaseContext.logClient().ClearLog( time, mBaseContext.reqStatus() );
       
    50     }
       
    51     else{
       
    52         mBaseContext.logClient().ClearLog( mContext.clearType(), mBaseContext.reqStatus());
       
    53     }
       
    54     return true;
       
    55 }
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 //
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 bool LogsRemoveStateClearAll::continueL()
       
    62 {
       
    63     return enterNextStateL();
       
    64 }
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // LogsRemoveStateInit
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 bool LogsRemoveStateInit::enterL()
       
    71 {
       
    72     mBaseContext.index() = 0;
       
    73     if ( mBaseContext.isRecentView() && 
       
    74             static_cast<CLogViewRecent&>( mBaseContext.logView() ).SetRecentListL( 
       
    75                 KLogNullRecentList, mBaseContext.reqStatus() ) ){
       
    76         return true;
       
    77     }
       
    78     return enterNextStateL();
       
    79 }
       
    80 
       
    81 // ----------------------------------------------------------------------------
       
    82 //
       
    83 // ----------------------------------------------------------------------------
       
    84 //
       
    85 bool LogsRemoveStateInit::continueL()
       
    86 {
       
    87     return enterNextStateL();
       
    88 }
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // LogsRemoveStateDelete
       
    92 // ----------------------------------------------------------------------------
       
    93 //
       
    94 bool LogsRemoveStateDelete::enterL()
       
    95 {
       
    96     mRemoveIndex = 0;
       
    97     if ( deleteNextEvent() ){
       
    98         return true;
       
    99     }
       
   100     return enterNextStateL();
       
   101 }
       
   102 
       
   103 // ----------------------------------------------------------------------------
       
   104 //
       
   105 // ----------------------------------------------------------------------------
       
   106 //
       
   107 bool LogsRemoveStateDelete::continueL()
       
   108 {
       
   109     if ( deleteNextEvent() ){
       
   110         return true;
       
   111     }
       
   112     return enterNextStateL();
       
   113 }
       
   114 
       
   115 // ----------------------------------------------------------------------------
       
   116 //
       
   117 // ----------------------------------------------------------------------------
       
   118 //
       
   119 bool LogsRemoveStateDelete::deleteNextEvent()
       
   120 {
       
   121     bool deleting(false);
       
   122     if ( mRemoveIndex < mContext.removedEvents().count() ){
       
   123         int currId = mContext.removedEvents().at(mRemoveIndex);
       
   124         LOGS_QDEBUG_2( "logs [ENG]  LogsRemove::DeleteNextEvent, id: ", currId )
       
   125         mBaseContext.logClient().DeleteEvent( currId, mBaseContext.reqStatus() );
       
   126         deleting = true;
       
   127         mRemoveIndex++;
       
   128     }
       
   129     return deleting;
       
   130 }
       
   131 
       
   132 // ----------------------------------------------------------------------------
       
   133 // LogsRemoveStateDeleteDuplicates
       
   134 // ----------------------------------------------------------------------------
       
   135 //
       
   136 bool LogsRemoveStateDeleteDuplicates::enterL()
       
   137 {
       
   138     mDeleting = false;
       
   139     mBaseContext.index() = 0;
       
   140     mDeleteDuplicateIds.clear();
       
   141     
       
   142     // Duplicate deletion supported only for one event at the time
       
   143     if ( mContext.removedEvents().count() == 1 && 
       
   144          event().Id() == mBaseContext.currentEventId() &&
       
   145          duplicatesL() ){
       
   146         return true;
       
   147     }
       
   148     return enterNextStateL();
       
   149 }
       
   150 
       
   151 // ----------------------------------------------------------------------------
       
   152 //
       
   153 // ----------------------------------------------------------------------------
       
   154 //
       
   155 bool LogsRemoveStateDeleteDuplicates::continueL()
       
   156 {
       
   157     bool continueFindingDuplicates = false;
       
   158     if ( !mDeleting && mBaseContext.duplicatesView().CountL() > 0  && 
       
   159          mBaseContext.index() <= mBaseContext.duplicatesView().CountL() ) {
       
   160         LOGS_QDEBUG( "logs [ENG] duplicates exist!");
       
   161         if ( mBaseContext.index() == 0 ){
       
   162             continueFindingDuplicates = 
       
   163                 mBaseContext.duplicatesView().FirstL(mBaseContext.reqStatus());
       
   164             mBaseContext.index()++; 
       
   165         } else {
       
   166             mDeleteDuplicateIds.append( mBaseContext.duplicatesView().Event().Id() );
       
   167             continueFindingDuplicates = 
       
   168                 mBaseContext.duplicatesView().NextL(mBaseContext.reqStatus());
       
   169             mBaseContext.index()++; 
       
   170         } 
       
   171     } 
       
   172     if ( continueFindingDuplicates || deleteNextEvent() ){
       
   173         return true;
       
   174     }
       
   175     return enterNextStateL();
       
   176 }
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 //
       
   180 // ----------------------------------------------------------------------------
       
   181 //
       
   182 bool LogsRemoveStateDeleteDuplicates::deleteNextEvent()
       
   183 {
       
   184     mDeleting = false;
       
   185     if ( !mDeleteDuplicateIds.isEmpty() ){
       
   186         int currId = mDeleteDuplicateIds.takeFirst();
       
   187         LOGS_QDEBUG_2( "logs [ENG]  LogsRemoveStateDeleteDuplicates::deleteNextEvent id: ", 
       
   188                        currId )
       
   189         mBaseContext.logClient().DeleteEvent( currId, mBaseContext.reqStatus() );
       
   190         mDeleting = true;
       
   191     }
       
   192     return mDeleting;
       
   193 }
       
   194 
       
   195 // ----------------------------------------------------------------------------
       
   196 // LogsRemoveStateDone
       
   197 // ----------------------------------------------------------------------------
       
   198 //
       
   199 bool LogsRemoveStateDone::enterL()
       
   200 {
       
   201     mContext.observer().removeCompleted();
       
   202     return false;
       
   203 }
       
   204 
       
   205 // CONSTANTS