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