menufw/hierarchynavigator/hnpresentationmodel/src/hnattributeimage.cpp
changeset 0 f72a12da539e
child 54 1b758917cafc
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  image attribute model
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bautils.h>
       
    20 #include <f32file.h>
       
    21 #include <liwcommon.h>
       
    22 
       
    23 #include "hnglobals.h"
       
    24 #include "hnattributeimage.h"
       
    25 #include "hnattrimgprovider.h"
       
    26 #include "hnattrimgprovthememif.h"
       
    27 #include "hnattrimgprovappimage.h"
       
    28 #include "hnattrimgprovfileimage.h"
       
    29 #include "hnattrimgprovliwimage.h"
       
    30 #include "hnattrimgprovemptyimage.h"
       
    31 #include "hnattrimgprovsvgimage.h"
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CHnAttributeImage::CHnAttributeImage()
       
    40     {
       
    41     iSkinId = KAknsIIDNone;
       
    42     iAttributeType = EImageAttribute;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CHnAttributeImage::~CHnAttributeImage()
       
    50     {
       
    51     iFileNameSrc.Close();
       
    52     iMifFile.Close();
       
    53     RemoveLiwObjects();
       
    54     delete iAttrImgProvider;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CHnAttributeImage* CHnAttributeImage::NewL()
       
    62     {
       
    63     CHnAttributeImage* self = NewLC();
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 EXPORT_C CHnAttributeImage* CHnAttributeImage::NewLC()
       
    73     {
       
    74     CHnAttributeImage* self = new ( ELeave ) CHnAttributeImage;
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     return self;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CHnAttributeImage::ConstructL()
       
    85     {
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 EXPORT_C void CHnAttributeImage::SetSkinId(TAknsItemID aSkinId)
       
    93     {
       
    94     iSkinId = aSkinId ;
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C void CHnAttributeImage::SetFileNameSrc(HBufC* aFileNameSrc)
       
   102     {
       
   103     iFileNameSrc.Assign( aFileNameSrc );
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C void CHnAttributeImage::SetMifFile(HBufC* aMifFile)
       
   111     {
       
   112     iMifFile.Assign( aMifFile );
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 EXPORT_C void CHnAttributeImage::SetBitmapId(TInt aBitmapId)
       
   120     {
       
   121     iBitmapId = aBitmapId ;
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C void CHnAttributeImage::SetMaskId(TInt aMaskId)
       
   129     {
       
   130     iMaskId = aMaskId ;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 EXPORT_C void CHnAttributeImage::SetApplicationUid(TUid aApplicationUid)
       
   138     {
       
   139     iApplicationUid = aApplicationUid ;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 EXPORT_C void CHnAttributeImage::SetBitmap( TLiwVariant* aBitmap )
       
   147     {
       
   148     iBitmap = aBitmap ;
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C void CHnAttributeImage::SetMask( TLiwVariant* aMask )
       
   156     {
       
   157     iMask = aMask ;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 TInt CHnAttributeImage::Prepare()
       
   165     {
       
   166     TInt error = KErrNone;
       
   167     if( !iAttrImgProvider )
       
   168         {
       
   169         TRAP( error, PrepareProviderL() );
       
   170         }
       
   171     return error;
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void CHnAttributeImage::PrepareProviderL()
       
   179     {
       
   180     ASSERT( !iAttrImgProvider );
       
   181     if ( IsThemeMif() )
       
   182         {
       
   183         iAttrImgProvider = CHnAttrImgProvThemeMif::NewL( iSkinId, iMifFile, 
       
   184                 iBitmapId, iMaskId );
       
   185         }
       
   186     else if ( IsApplicationImage() )
       
   187         {
       
   188         iAttrImgProvider = CHnAttrImgProvAppImage::NewL( iApplicationUid );
       
   189         }
       
   190     else if ( IsFileImageL() )
       
   191         {
       
   192         if ( iFileNameSrc.Find( KSvgFileExtension() ) != KErrNotFound )
       
   193         	{
       
   194         	iAttrImgProvider = CHnAttrImgProvSvgImage::NewL( iFileNameSrc );
       
   195         	}
       
   196         else
       
   197         	{
       
   198         	iAttrImgProvider = CHnAttrImgProvFileImage::NewL( iFileNameSrc );
       
   199         	}
       
   200         }
       
   201     else if ( IsLiwImage() )
       
   202         {
       
   203         iAttrImgProvider = CHnAttrImgProvLiwImage::NewL( iBitmap, iMask );
       
   204         }
       
   205     // if strin couldn't be resolved then provide empty one
       
   206     else
       
   207         {
       
   208         iAttrImgProvider = CHnAttrImgProvEmptyImage::NewL();
       
   209         }
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 TBool CHnAttributeImage::IsThemeMif()
       
   217     {
       
   218     if( iSkinId != KAknsIIDNone )
       
   219         {
       
   220         return ETrue;
       
   221         }
       
   222     if( iMifFile.Length() && iBitmapId && iMaskId )
       
   223         {
       
   224         return ETrue;
       
   225         }
       
   226     return EFalse;
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 TBool CHnAttributeImage::IsApplicationImage()
       
   234     {
       
   235     TBool ret( EFalse );
       
   236     if ( iApplicationUid.iUid != 0 )
       
   237         {
       
   238         ret = ETrue;
       
   239         }
       
   240     return ret;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // 
       
   245 // ---------------------------------------------------------------------------
       
   246 // 
       
   247 TBool CHnAttributeImage::IsFileImageL()
       
   248     {
       
   249     TBool ret( EFalse );
       
   250     if ( iFileNameSrc.Length() > 0  )
       
   251         {
       
   252         RFs& fs = CEikonEnv::Static()->FsSession();
       
   253         
       
   254         if ( BaflUtils::FileExists( fs, iFileNameSrc ) )
       
   255             {
       
   256             ret = ETrue;
       
   257             }
       
   258         }
       
   259     return ret;
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // 
       
   264 // ---------------------------------------------------------------------------
       
   265 // 
       
   266 TBool CHnAttributeImage::IsLiwImage()
       
   267     {
       
   268     TBool ret( EFalse );
       
   269     if ( iBitmap )
       
   270         {
       
   271         ret = ETrue;
       
   272         }
       
   273     return ret;
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // 
       
   278 // ---------------------------------------------------------------------------
       
   279 // 
       
   280 EXPORT_C CGulIcon* CHnAttributeImage::GetIcon( TSize* aDesiredIconSize )
       
   281     { 
       
   282     if ( Prepare() == KErrNone )
       
   283         {
       
   284         return iAttrImgProvider->GetIcon( aDesiredIconSize );
       
   285         }
       
   286     else 
       
   287         {
       
   288         return NULL;
       
   289         }
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // 
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 CHnIconHolder* CHnAttributeImage::GetIconHolder( TSize* aDesiredIconSize )
       
   297 {
       
   298     CHnIconHolder* iconHolder = NULL;
       
   299     if ( Prepare() == KErrNone )
       
   300         {
       
   301         iconHolder = iAttrImgProvider->GetIconHolder( aDesiredIconSize );
       
   302         }
       
   303     return iconHolder;
       
   304 }
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // 
       
   308 // ---------------------------------------------------------------------------
       
   309 // 
       
   310 void CHnAttributeImage::RemoveLiwObjects()
       
   311     {
       
   312     if ( iAttrImgProvider )
       
   313         {
       
   314         iAttrImgProvider->RemoveLiwObjects();
       
   315         }
       
   316 
       
   317     if( iBitmap )
       
   318         {
       
   319         iBitmap->Reset();
       
   320         delete iBitmap;
       
   321         iBitmap = NULL;
       
   322         }
       
   323 
       
   324     if( iMask )
       
   325         {
       
   326         iMask->Reset();
       
   327         delete iMask;
       
   328         iMask = NULL;
       
   329         }
       
   330     }