phonebookui/Phonebook2/xSPExtensionManager/src/CxSPViewInfo.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2006 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 *       xSP view info
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <AknIconUtils.h>
       
    22 #include <coemain.h>
       
    23 #include <barsread.h>
       
    24 #include <f32file.h>
       
    25 
       
    26 #include "MxSPViewInfo.h"
       
    27 #include "CxSPViewInfo.h"
       
    28 #include "TNewViewIdInfo.h"
       
    29 #include "ExtensionManagerIcons.hrh"
       
    30 
       
    31 namespace {
       
    32 
       
    33 // CONSTANTS
       
    34 _LIT( K_MBM_FILE_LOCATION, "\\resource\\ExtensionManager.mbm" );
       
    35 }
       
    36 
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 // ==================== MEMBER FUNCTIONS ====================
       
    41 CxSPViewInfo::CxSPViewInfo( TUint32 aId ) : iId( aId ),
       
    42 											iNewViewId( KErrNotFound )   
       
    43     {
       
    44     }
       
    45 
       
    46 CxSPViewInfo::~CxSPViewInfo()
       
    47     { 
       
    48     delete iTabIconFile;
       
    49     delete iName;
       
    50     delete iSortIconFile;   
       
    51     }
       
    52 
       
    53 CxSPViewInfo* CxSPViewInfo::NewLC( TResourceReader& aReader, TUint32 aId )
       
    54     {
       
    55     CxSPViewInfo* self = new (ELeave) CxSPViewInfo( aId );
       
    56     CleanupStack::PushL(self);
       
    57     self->ConstructL( aReader );
       
    58     return self;
       
    59     }
       
    60     
       
    61 CxSPViewInfo* CxSPViewInfo::NewLC( const MxSPViewInfo& aInfo, TUint32 aId )
       
    62 	{
       
    63 	CxSPViewInfo* self = new (ELeave) CxSPViewInfo( aId );
       
    64     CleanupStack::PushL(self);
       
    65     self->ConstructL( aInfo );
       
    66     return self;
       
    67 	}
       
    68         
       
    69 void CxSPViewInfo::ConstructL( TResourceReader& aReader )
       
    70     {
       
    71     iOldViewId = aReader.ReadInt32();
       
    72     iTabView = aReader.ReadInt32();
       
    73     iTabIconId = aReader.ReadInt32();
       
    74     iTabMaskId = aReader.ReadInt32();
       
    75     HBufC* pathAndFile = aReader.ReadHBufCL();
       
    76     CleanupStack::PushL( pathAndFile );
       
    77     TFindFile findFile( CCoeEnv::Static()->FsSession() );
       
    78     TInt err = findFile.FindByDir( *pathAndFile, KNullDesC );
       
    79     if( err )
       
    80     	{
       
    81     	iTabIconFile = KNullDesC().AllocL();
       
    82     	}
       
    83     else
       
    84     	{
       
    85     	iTabIconFile = findFile.File().AllocL();
       
    86     	}    
       
    87     CleanupStack::PopAndDestroy( pathAndFile );
       
    88     pathAndFile = NULL;
       
    89     
       
    90     TBool tabIconOk = IsBitmapCreatable( *iTabIconFile, iTabIconId );
       
    91 	TBool tabMaskOk = IsBitmapCreatable( *iTabIconFile, iTabMaskId );
       
    92     if( !tabIconOk || !tabMaskOk )
       
    93     	{
       
    94     	iTabIconId = qgn_empty_tab;
       
    95     	iTabMaskId = qgn_empty_tab_mask;
       
    96     	findFile.FindByDir( K_MBM_FILE_LOCATION(), KNullDesC );
       
    97     	delete iTabIconFile;
       
    98     	iTabIconFile = NULL;
       
    99     	iTabIconFile = findFile.File().AllocL();
       
   100     	}	
       
   101         
       
   102     iName = aReader.ReadHBufCL();
       
   103     if( !iName )
       
   104     	{
       
   105     	iName = KNullDesC().AllocL();
       
   106     	}
       
   107     iSortIconId = aReader.ReadInt32();
       
   108     iSortMaskId = aReader.ReadInt32();
       
   109         
       
   110     pathAndFile = aReader.ReadHBufCL();
       
   111     CleanupStack::PushL( pathAndFile );
       
   112     err = findFile.FindByDir( *pathAndFile, KNullDesC );
       
   113     if( err )
       
   114     	{
       
   115     	iSortIconFile = KNullDesC().AllocL();
       
   116     	}
       
   117     else
       
   118     	{
       
   119     	iSortIconFile = findFile.File().AllocL();
       
   120     	}    
       
   121     CleanupStack::PopAndDestroy( pathAndFile );
       
   122     
       
   123     TBool sortIconOk = IsBitmapCreatable( *iSortIconFile, iSortIconId );
       
   124 	TBool sortMaskOk = IsBitmapCreatable( *iSortIconFile, iSortMaskId );
       
   125     if( !sortIconOk || !sortMaskOk )
       
   126     	{
       
   127     	iSortIconId = qgn_empty_tab;
       
   128     	iSortMaskId = qgn_empty_tab_mask;
       
   129     	findFile.FindByDir( K_MBM_FILE_LOCATION(), KNullDesC );
       
   130     	delete iSortIconFile;
       
   131     	iSortIconFile = NULL;
       
   132     	iSortIconFile = findFile.File().AllocL();
       
   133     	}	
       
   134     }
       
   135  
       
   136 void CxSPViewInfo::ConstructL( const MxSPViewInfo& aInfo )
       
   137 	{
       
   138 	iOldViewId = aInfo.OldViewId();
       
   139     iTabView = aInfo.TabView();
       
   140     iTabIconId = aInfo.TabIconId();
       
   141     iTabMaskId = aInfo.TabMaskId();
       
   142     HBufC* pathAndFile = aInfo.TabIconFile().AllocL();
       
   143     CleanupStack::PushL( pathAndFile );
       
   144     TFindFile findFile( CCoeEnv::Static()->FsSession() );
       
   145     TInt err = findFile.FindByDir( *pathAndFile, KNullDesC );
       
   146     if( err )
       
   147     	{
       
   148     	iTabIconFile = KNullDesC().AllocL();
       
   149     	}
       
   150     else
       
   151     	{
       
   152     	iTabIconFile = findFile.File().AllocL();
       
   153     	}    
       
   154     CleanupStack::PopAndDestroy( pathAndFile );
       
   155     pathAndFile = NULL;
       
   156     
       
   157     TBool tabIconOk = IsBitmapCreatable( *iTabIconFile, iTabIconId );
       
   158 	TBool tabMaskOk = IsBitmapCreatable( *iTabIconFile, iTabMaskId );
       
   159     if( !tabIconOk || !tabMaskOk )
       
   160     	{
       
   161     	iTabIconId = qgn_empty_tab;
       
   162     	iTabMaskId = qgn_empty_tab_mask;
       
   163     	findFile.FindByDir( K_MBM_FILE_LOCATION(), KNullDesC );
       
   164     	delete iTabIconFile;
       
   165     	iTabIconFile = NULL;
       
   166     	iTabIconFile = findFile.File().AllocL();
       
   167     	}
       
   168     	
       
   169     iName = aInfo.Name().AllocL();
       
   170     
       
   171     iSortIconId = aInfo.SortIconId();
       
   172     iSortMaskId = aInfo.SortMaskId();
       
   173     
       
   174     pathAndFile = aInfo.SortIconFile().AllocL();
       
   175     CleanupStack::PushL( pathAndFile );
       
   176     err = findFile.FindByDir( *pathAndFile, KNullDesC );
       
   177     if( err )
       
   178     	{
       
   179     	iSortIconFile = KNullDesC().AllocL();
       
   180     	}
       
   181     else
       
   182     	{
       
   183     	iSortIconFile = findFile.File().AllocL();
       
   184     	}    
       
   185     CleanupStack::PopAndDestroy( pathAndFile );
       
   186     
       
   187     TBool sortIconOk = IsBitmapCreatable( *iSortIconFile, iSortIconId );
       
   188 	TBool sortMaskOk = IsBitmapCreatable( *iSortIconFile, iSortMaskId );
       
   189     if( !sortIconOk || !sortMaskOk )
       
   190     	{
       
   191     	iSortIconId = qgn_empty_tab;
       
   192     	iSortMaskId = qgn_empty_tab_mask;
       
   193     	findFile.FindByDir( K_MBM_FILE_LOCATION(), KNullDesC );
       
   194     	delete iSortIconFile;
       
   195     	iSortIconFile = NULL;
       
   196     	iSortIconFile = findFile.File().AllocL();
       
   197     	}
       
   198 	}
       
   199     
       
   200 TInt CxSPViewInfo::SetNewId( RArray<TNewViewIdInfo>& aPool )
       
   201 	{
       
   202 	TInt err( KErrNotFound);
       
   203 	const TInt count = aPool.Count();
       
   204 	for( TInt i = 0; i < count && err; i++ )
       
   205 		{
       
   206 		TNewViewIdInfo& info = aPool[i];
       
   207 		if( info.iFree )
       
   208 			{
       
   209 			info.iFree = EFalse;
       
   210 			err = KErrNone;
       
   211 			iNewViewId = info.iId;
       
   212 			}
       
   213 		}		
       
   214 	return err;
       
   215 	}
       
   216 
       
   217 TUint32 CxSPViewInfo::Id() const
       
   218 	{
       
   219 	return iId;	
       
   220 	}
       
   221 	
       
   222 TInt32 CxSPViewInfo::NewViewId() const
       
   223 	{
       
   224 	return iNewViewId;	
       
   225 	}
       
   226 
       
   227 TInt32 CxSPViewInfo::OldViewId() const
       
   228 	{
       
   229 	return iOldViewId;	
       
   230 	}
       
   231 
       
   232 TBool CxSPViewInfo::TabView() const
       
   233 	{
       
   234 	if ( iTabView == 0 ) 
       
   235 		{
       
   236 		return EFalse;
       
   237 		}
       
   238 	else
       
   239 		{
       
   240 		return ETrue;
       
   241 		}
       
   242 	}
       
   243 
       
   244 TInt32 CxSPViewInfo::TabIconId() const
       
   245 	{
       
   246 	return iTabIconId;	
       
   247 	}
       
   248 
       
   249 TInt32 CxSPViewInfo::TabMaskId() const
       
   250 	{
       
   251 	return iTabMaskId;	
       
   252 	}
       
   253 
       
   254 const TDesC& CxSPViewInfo::TabIconFile() const
       
   255 	{
       
   256 	return *iTabIconFile;	
       
   257 	}
       
   258 	
       
   259 const TDesC& CxSPViewInfo::Name() const
       
   260 	{
       
   261 	return *iName;
       
   262 	}
       
   263         
       
   264 TInt32 CxSPViewInfo::SortIconId() const
       
   265 	{
       
   266 	return iSortIconId;
       
   267 	}
       
   268 
       
   269 TInt32 CxSPViewInfo::SortMaskId() const
       
   270 	{
       
   271 	return iSortMaskId;
       
   272 	}
       
   273 
       
   274 const TDesC& CxSPViewInfo::SortIconFile() const
       
   275 	{
       
   276 	return *iSortIconFile;
       
   277 	}
       
   278 	
       
   279 TBool CxSPViewInfo::IsBitmapCreatable( const TDesC& aFileName, TInt aId )
       
   280 	{	
       
   281 	TBool result( EFalse );
       
   282 	if( aFileName.Length() && aId >= 0 )
       
   283 		{
       
   284 		CFbsBitmap* bitmap = NULL;	
       
   285 		TInt err;	
       
   286 		TRAP( err, bitmap = AknIconUtils::CreateIconL( aFileName, aId ) );
       
   287 		if( !err )
       
   288 			{
       
   289 			delete bitmap;
       
   290 			result = ETrue;
       
   291 			}	
       
   292 		}			
       
   293 	return result;						
       
   294 	}
       
   295 			       
       
   296 // end of file