Common/Src/IEImageData.cpp
changeset 3 93fff7023be8
equal deleted inserted replaced
2:e1e28b0273b0 3:93fff7023be8
       
     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: Juha Kauppinen, Mika Hokkanen
       
    13 * 
       
    14 * Description: Photo Browser
       
    15 *
       
    16 */
       
    17 
       
    18 // Include files
       
    19 #include <eikenv.h>
       
    20 #include "IEImageData.h"
       
    21 #include "ImagicConsts.h"
       
    22 
       
    23 EXPORT_C CImageData* CImageData::NewL(TUint32 aImagesReady)
       
    24     {
       
    25     CImageData* self = new (ELeave) CImageData();
       
    26     CleanupStack::PushL(self);
       
    27     self->ConstructL(aImagesReady);
       
    28     CleanupStack::Pop();
       
    29     return self;
       
    30     }
       
    31 
       
    32 EXPORT_C CImageData::~CImageData()
       
    33     {
       
    34     delete iFileName;
       
    35     delete iPath;
       
    36     }
       
    37 
       
    38 CImageData::CImageData() : 
       
    39     iFileTime(0),
       
    40     iCreatedTime(0)
       
    41     {
       
    42     }
       
    43 
       
    44 void CImageData::ConstructL(TUint32 aImagesReady)
       
    45     {
       
    46     iFileName = NULL;
       
    47     iPath = NULL;
       
    48     iGridData.iCorrupted = 0;
       
    49     iGridData.iRotationAngle = 0;
       
    50     iGridData.iTargetRotationAngle = 0;
       
    51     iGridData.iX = iGridData.iY = iGridData.iZ = 0;
       
    52     iGridData.iScale = 0;
       
    53     iGridData.iGlLQ32TextIndex = 0;
       
    54     iGridData.iGlLQ128TextIndex = 0;
       
    55     iGridData.iGlHQ512TextIndex = 0;
       
    56     iGridData.iGlSuperHQTextIndex = 0;
       
    57     iImagesReady = aImagesReady|EExifThumb;
       
    58     iOrientation = 0;
       
    59     iNumberOfFaces = -1;
       
    60     iAspectRatio = 1;
       
    61     iSize = TSize(0,0);
       
    62     iPersonId = -1;
       
    63     }
       
    64 
       
    65 EXPORT_C void CImageData::SetFileNameL(const TFileName & aFileName) 
       
    66     {
       
    67     TParse parser;
       
    68     parser.Set(aFileName, NULL, NULL);
       
    69     delete iFileName; iFileName = NULL;
       
    70     delete iPath; iPath = NULL;
       
    71     iFileName = parser.NameAndExt().AllocL();
       
    72     iPath = parser.DriveAndPath().AllocL();
       
    73     }
       
    74 
       
    75 EXPORT_C void CImageData::GetFileName(TFileName & aFullFileName, TThumbSize aSize) const 
       
    76     {
       
    77     if (iPath == NULL || iFileName == NULL)
       
    78         User::Leave(KErrNotReady);
       
    79         
       
    80     aFullFileName = *iPath;
       
    81 
       
    82     switch (aSize) 
       
    83         { 
       
    84         case EFullSize:
       
    85             aFullFileName.Append(*iFileName);
       
    86             break;
       
    87 
       
    88         case ESize32x32:
       
    89             aFullFileName.Append(K32x32TNFilePath);
       
    90             aFullFileName.Append(*iFileName);
       
    91             aFullFileName.Append(K32x32Ext);
       
    92             break;            
       
    93             
       
    94         case ESize128x128:
       
    95             aFullFileName.Append(K128x128TNFilePath);
       
    96             aFullFileName.Append(*iFileName);
       
    97             aFullFileName.Append(K128x128Ext);            
       
    98             break;  
       
    99             
       
   100         case ESize512x512:
       
   101             aFullFileName.Append(K512x512TNFilePath);
       
   102             aFullFileName.Append(*iFileName);
       
   103             aFullFileName.Append(K512x512Ext);            
       
   104             break;  
       
   105 
       
   106         default:
       
   107             User::Leave(KErrArgument);
       
   108         }
       
   109     }
       
   110 
       
   111 EXPORT_C void CImageData::GetPath(TFileName & aPath) const 
       
   112     {
       
   113     aPath.Copy(iPath ? iPath->Des() : _L(""));
       
   114     }
       
   115 
       
   116 EXPORT_C void CImageData::GetFileName(TFileName & aFileName) const
       
   117     {
       
   118     aFileName.Copy(iFileName ? iFileName->Des() : _L(""));
       
   119     }
       
   120 
       
   121 EXPORT_C TBool CImageData::IsImageReady(TThumbSize aSize) const 
       
   122     {
       
   123     return ((iImagesReady & aSize) == aSize);
       
   124     }
       
   125 
       
   126 EXPORT_C void CImageData::SetImageReady(TThumbSize aSize, TBool aReady)  
       
   127     {
       
   128     if (aReady) 
       
   129         iImagesReady |= aSize;
       
   130     else
       
   131         iImagesReady &= ~aSize;
       
   132     }
       
   133 
       
   134 EXPORT_C const TReal CImageData::GetAspectRatio() const 
       
   135     { 
       
   136     return iAspectRatio;
       
   137     }
       
   138 
       
   139 TBool CImageData::IsCreatedTimeSet() const 
       
   140     {
       
   141     // Time is defined if not zero
       
   142     return (iCreatedTime.Int64() != 0);
       
   143     }
       
   144 
       
   145 EXPORT_C const TTime & CImageData::GetFileTime() const 
       
   146     { 
       
   147     return iFileTime; 
       
   148     }
       
   149 
       
   150 EXPORT_C void CImageData::SetFileTime(const TTime & aTime) 
       
   151     { 
       
   152     iFileTime = aTime;
       
   153     }
       
   154 
       
   155 EXPORT_C const TTime & CImageData::GetCreatedTime() const 
       
   156     { 
       
   157     // if no created time (usually from EXIF), use file time
       
   158     return IsCreatedTimeSet() ? iCreatedTime : iFileTime; 
       
   159     }
       
   160 
       
   161 EXPORT_C void CImageData::SetCreatedTime(const TTime & aTime) 
       
   162     { 
       
   163     iCreatedTime = aTime; 
       
   164     }
       
   165 
       
   166 EXPORT_C TUint16 CImageData::GetOrientation() const 
       
   167     {
       
   168     return iOrientation;
       
   169     }
       
   170 
       
   171 EXPORT_C void CImageData::SetOrientation(TUint16 aOrientation) 
       
   172     {
       
   173     iOrientation = aOrientation;
       
   174     }
       
   175 
       
   176 EXPORT_C void CImageData::SetSize(const TSize aSize)
       
   177     {
       
   178     iSize = aSize;
       
   179     iAspectRatio = iSize.iHeight ? (TReal(iSize.iWidth) / iSize.iHeight) : 0;
       
   180     }
       
   181 
       
   182 EXPORT_C TSize CImageData::GetSize() const
       
   183     {
       
   184     return iSize;
       
   185     }
       
   186 
       
   187 EXPORT_C TInt CImageData::GetNumberOfFaces() const 
       
   188     {
       
   189     return iNumberOfFaces;
       
   190     }
       
   191 
       
   192 EXPORT_C void CImageData::SetNumberOfFaces(TInt aValue) 
       
   193     {
       
   194     iNumberOfFaces = aValue;
       
   195     }
       
   196 
       
   197 EXPORT_C TBool CImageData::IsSamePath(CImageData& aImageData) const
       
   198     {
       
   199     TFileName path, path2;
       
   200     GetPath(path);
       
   201     aImageData.GetPath(path2);
       
   202     return (path == path2);
       
   203     }