phonebookui/Phonebook/View/src/CPbkThumbnailReaderBase.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 *       Provides methods for CPbkThumbnailManager implementation classes.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkThumbnailReaderBase.h"
       
    22 #include "CPbkImageReader.h"
       
    23 #include "MPbkThumbnailOperationObservers.h"
       
    24 #include "PbkImageData.h"
       
    25 
       
    26 #include <fbs.h>
       
    27 #include <imageconversion.h>
       
    28 
       
    29 namespace {
       
    30 
       
    31 enum TPanicCode
       
    32     {
       
    33     EPanicPreCond_CancelRead = 1,
       
    34     EPanicPreCond_StartReadL,
       
    35     EPanic_ImageReadComplete_Called,
       
    36     EPanic_ImageReadFailed_Called
       
    37     };
       
    38 
       
    39 #ifdef _DEBUG
       
    40 void Panic(TPanicCode aPanicCode)
       
    41     {
       
    42     _LIT(KPanicText, "CPbkThumbnailReaderBase");
       
    43     User::Panic(KPanicText, aPanicCode);
       
    44     }
       
    45 #endif
       
    46 
       
    47 } // namespace
       
    48 
       
    49 // ================= MEMBER FUNCTIONS =======================
       
    50 
       
    51 CPbkThumbnailReaderBase::CPbkThumbnailReaderBase
       
    52         (MPbkThumbnailGetObserver& aObserver) :
       
    53     iObserver(aObserver)
       
    54     {
       
    55     }
       
    56 
       
    57 void CPbkThumbnailReaderBase::ConstructL()
       
    58     {
       
    59     iImageReader = CPbkImageReader::NewL(*this);
       
    60     }
       
    61 
       
    62 CPbkThumbnailReaderBase::~CPbkThumbnailReaderBase()
       
    63     {
       
    64     delete iImageReader;
       
    65     }
       
    66 
       
    67 void CPbkThumbnailReaderBase::CancelRead()
       
    68     {
       
    69     __ASSERT_DEBUG(iImageReader, Panic(EPanicPreCond_CancelRead));
       
    70     iImageReader->Cancel();
       
    71     }
       
    72 
       
    73 void CPbkThumbnailReaderBase::ImageReadComplete
       
    74         (CPbkImageReader& /*aReader*/, CFbsBitmap* aBitmap)
       
    75     {
       
    76     iObserver.PbkThumbnailGetComplete(*this,aBitmap);
       
    77     }
       
    78 
       
    79 void CPbkThumbnailReaderBase::ImageReadFailed
       
    80         (CPbkImageReader& /*aReader*/, TInt aError)
       
    81     {
       
    82     iObserver.PbkThumbnailGetFailed(*this,aError);
       
    83     }
       
    84 
       
    85 
       
    86 // CPbkThumbnailImageReaderBase
       
    87 CPbkThumbnailImageReaderBase::CPbkThumbnailImageReaderBase
       
    88         (MPbkThumbnailGetImageObserver& aObserver) :
       
    89     iObserver(aObserver)
       
    90     {
       
    91     }
       
    92 
       
    93 void CPbkThumbnailImageReaderBase::ConstructL()
       
    94     {
       
    95     iImageReader = CPbkImageReader::NewL(*this);
       
    96     }
       
    97 
       
    98 CPbkThumbnailImageReaderBase::~CPbkThumbnailImageReaderBase()
       
    99     {
       
   100     delete iImageData;
       
   101     delete iImageReader;
       
   102     }
       
   103 
       
   104 void CPbkThumbnailImageReaderBase::StartReadL(const TPbkImageLoadParameters* aParameters)
       
   105     {
       
   106     __ASSERT_DEBUG(iImageReader, Panic(EPanicPreCond_StartReadL));
       
   107     CancelRead();
       
   108     DoStartReadL(aParameters);
       
   109     }
       
   110 
       
   111 void CPbkThumbnailImageReaderBase::CancelRead()
       
   112     {
       
   113     __ASSERT_DEBUG(iImageReader, Panic(EPanicPreCond_CancelRead));
       
   114     iImageReader->Cancel();
       
   115     delete iImageData;
       
   116     iImageData = NULL;
       
   117     }
       
   118 
       
   119 void CPbkThumbnailImageReaderBase::ImageReadComplete
       
   120         (CPbkImageReader& /*aReader*/, CFbsBitmap* aBitmap)
       
   121     {
       
   122     // this does not get called because reading is canceled 
       
   123     // when opening completes
       
   124     __ASSERT_DEBUG(EFalse, Panic(EPanic_ImageReadComplete_Called));
       
   125     delete aBitmap;
       
   126     }
       
   127 
       
   128 void CPbkThumbnailImageReaderBase::ImageReadFailed
       
   129         (CPbkImageReader& /*aReader*/, TInt aError)
       
   130     {
       
   131     // this does not get called because reading is canceled 
       
   132     // when opening completes
       
   133     __ASSERT_DEBUG(EFalse, Panic(EPanic_ImageReadFailed_Called));
       
   134     iObserver.PbkThumbnailGetImageFailed(*this,aError);
       
   135     }
       
   136 
       
   137 void CPbkThumbnailImageReaderBase::ImageOpenComplete
       
   138         (CPbkImageReader& /*aReader*/)
       
   139     {
       
   140     TRAPD(err, HandleImageOpenCompleteL());
       
   141     // Cancel further reading of image
       
   142     iImageReader->Cancel();
       
   143     if (err)
       
   144         {
       
   145         iObserver.PbkThumbnailGetImageFailed(*this,err);
       
   146         }
       
   147     else
       
   148         {
       
   149         // Release ownership of iImageData
       
   150         CPbkImageDataWithInfo* imageData = iImageData;
       
   151         iImageData = NULL;
       
   152         iObserver.PbkThumbnailGetImageComplete(*this,imageData);
       
   153         }
       
   154     }
       
   155 
       
   156 void CPbkThumbnailImageReaderBase::HandleImageOpenCompleteL()
       
   157     {
       
   158     MPbkImageData* imageData = CreateImageDataLC();
       
   159 
       
   160     CPbkImageDataWithInfo::TParams params;
       
   161     params.iImageData = imageData;
       
   162     params.iMimeType = &iImageReader->MimeString();
       
   163     if (iImageReader->FrameCount() > 0)
       
   164         {
       
   165         TFrameInfo frameInfo;
       
   166         iImageReader->FrameInfo(0,frameInfo);
       
   167         params.iSizeInPixels = frameInfo.iOverallSizeInPixels;
       
   168         }
       
   169 
       
   170     iImageData = CPbkImageDataWithInfo::NewL(params);
       
   171     CleanupStack::Pop();  // imageData
       
   172     }
       
   173 
       
   174 //  End of File