engine/collectionframework/thumbnailcreator/src/glxtnfilteravailabletask.cpp
changeset 71 27f2d7aec52a
parent 69 45459746d5e8
child 72 0a8e959402e5
equal deleted inserted replaced
69:45459746d5e8 71:27f2d7aec52a
     1 /*
       
     2 * Copyright (c) 2008-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:   Task used for thumbnail availability filter.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  * @internal reviewed 31/07/2007 by Simon Brooks
       
    22  */
       
    23 
       
    24 #include "glxtnfilteravailabletask.h"
       
    25 
       
    26 #include <glxassert.h>
       
    27 #include <glxtracer.h>
       
    28 
       
    29 #include "glxtnfileinfo.h"
       
    30 #include "mglxtnstorage.h"
       
    31 #include "mglxtnthumbnailcreatorclient.h"
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // NewL
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CGlxtnFilterAvailableTask* CGlxtnFilterAvailableTask::NewL(
       
    38                     const TArray<TGlxMediaId>& aItemArray, const TSize& aSize,
       
    39                     MGlxtnThumbnailCreatorClient& aClient)
       
    40     {
       
    41     TRACER("CGlxtnFilterAvailableTask* CGlxtnFilterAvailableTask::NewL()");
       
    42     CGlxtnFilterAvailableTask* task = new (ELeave) CGlxtnFilterAvailableTask(
       
    43                                                                 aSize, aClient);
       
    44     CleanupStack::PushL(task);
       
    45     task->ConstructL(aItemArray);
       
    46     CleanupStack::Pop(task);
       
    47     return task;
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // Constructor
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CGlxtnFilterAvailableTask::CGlxtnFilterAvailableTask(const TSize& aSize,
       
    55                                         MGlxtnThumbnailCreatorClient& aClient) :
       
    56     CGlxtnClientTask(KGlxtnTaskIdFilterAvailable, KGlxIdNone, aClient),
       
    57     iSize(aSize)
       
    58     {
       
    59     TRACER("CGlxtnFilterAvailableTask::CGlxtnFilterAvailableTask()");
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // ConstructL
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CGlxtnFilterAvailableTask::ConstructL(
       
    67                                         const TArray<TGlxMediaId>& aItemArray)
       
    68     {
       
    69     TRACER("void CGlxtnFilterAvailableTask::ConstructL()");
       
    70     TInt count = aItemArray.Count();
       
    71     for ( TInt i = 0; i < count; i++ )
       
    72         {
       
    73         iIdArray.AppendL(aItemArray[i]);
       
    74         }
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // Destructor
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CGlxtnFilterAvailableTask::~CGlxtnFilterAvailableTask() 
       
    82     {
       
    83     TRACER("CGlxtnFilterAvailableTask::~CGlxtnFilterAvailableTask()");
       
    84     delete iFileInfo;
       
    85     iIdArray.Close();
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // DoStartL
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 TBool CGlxtnFilterAvailableTask::DoStartL(TRequestStatus& aStatus)
       
    93     {
       
    94     TRACER("TBool CGlxtnFilterAvailableTask::DoStartL()");
       
    95     iIndex = 0;
       
    96 
       
    97     GLX_ASSERT_DEBUG( !iFileInfo, Panic( EGlxPanicAlreadyInitialised ),
       
    98                         "iFileInfo not NULL" );
       
    99     iFileInfo = new (ELeave) CGlxtnFileInfo;
       
   100 
       
   101     return GetFileInfoL(aStatus);
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // DoCancel
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CGlxtnFilterAvailableTask::DoCancel() 
       
   109     {
       
   110     TRACER("void CGlxtnFilterAvailableTask::DoCancel()");
       
   111     Storage()->StorageCancel();
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // DoRunL
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 TBool CGlxtnFilterAvailableTask::DoRunL(TRequestStatus& aStatus) 
       
   119     {
       
   120     TRACER("TBool CGlxtnFilterAvailableTask::DoRunL()");
       
   121     TInt result = aStatus.Int();
       
   122     User::LeaveIfError(result);
       
   123 
       
   124     TBool active = EFalse;
       
   125 
       
   126     switch ( iState )
       
   127         {
       
   128         case EStateFetchingUri:
       
   129             Storage()->IsThumbnailAvailableL(iIdArray[iIndex], *iFileInfo,
       
   130                                                 iSize, &aStatus);
       
   131             iState = EStateChecking;
       
   132             active = ETrue;
       
   133             break;
       
   134 
       
   135         case EStateChecking:
       
   136             if ( KGlxThumbnailNotAvailable == result )
       
   137                 {
       
   138                 iIndex++;
       
   139                 }
       
   140             else
       
   141                 {
       
   142                 iIdArray.Remove(iIndex);
       
   143                 }
       
   144 
       
   145             active = GetFileInfoL(aStatus);
       
   146             break;
       
   147 
       
   148         default:
       
   149             GLX_ASSERT_ALWAYS( EFalse, Panic( EGlxPanicIllegalState ),
       
   150                             "CGlxtnFilterAvailableTask: Illegal state" );
       
   151             break;
       
   152         }
       
   153 
       
   154     return active; 
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // DoRunError
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 TBool CGlxtnFilterAvailableTask::DoRunError(TInt aError)
       
   162     {
       
   163     TRACER("CGlxtnFilterAvailableTask::DoRunError()");
       
   164     Client().FilterAvailableComplete(iIdArray, aError);
       
   165 
       
   166     return EFalse;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // GetFileInfoL
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TBool CGlxtnFilterAvailableTask::GetFileInfoL(TRequestStatus& aStatus)
       
   174     {
       
   175     TRACER("CGlxtnFilterAvailableTask::GetFileInfoL()");
       
   176     if ( iIndex < iIdArray.Count() )
       
   177         {
       
   178         Client().FetchFileInfoL(iFileInfo, iIdArray[iIndex], &aStatus);
       
   179         iState = EStateFetchingUri;
       
   180 
       
   181         return ETrue;
       
   182         }
       
   183 
       
   184     // Finished checking the array
       
   185     Client().FilterAvailableComplete(iIdArray, KErrNone);
       
   186 
       
   187     return EFalse;
       
   188     }