phonebookui/Phonebook2/xSPExtensionManager/src/CxSPViewIdChanger.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
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 id changer
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <coemain.h>
       
    22 #include <barsread.h>
       
    23 #include <centralrepository.h>
       
    24 
       
    25 
       
    26 #include "CxSPViewIdChanger.h"
       
    27 #include "MxSPFactory.h"
       
    28 #include "MxSPViewInfo.h"
       
    29 #include "ExtensionManager.hrh"
       
    30 #include "CxSPViewInfo.h"
       
    31 #include <ExtensionManagerRes.rsg>
       
    32 #include "ExtensionManagerUID.H"
       
    33 #include "xSPOrderOrganizer.h"
       
    34 #include "Phonebook2PrivateCRKeys.h"
       
    35 
       
    36 
       
    37 // CONSTANTS
       
    38 
       
    39 // ==================== MEMBER FUNCTIONS ====================
       
    40 CxSPViewIdChanger::CxSPViewIdChanger()
       
    41     {
       
    42     }
       
    43 
       
    44 CxSPViewIdChanger::~CxSPViewIdChanger()
       
    45     {
       
    46     iViewIdMap.ResetAndDestroy();
       
    47     iViewIdMap.Close();
       
    48     iTabViewNewIds.Close();
       
    49     iNonTabViewNewIds.Close();
       
    50     }
       
    51 
       
    52 CxSPViewIdChanger* CxSPViewIdChanger::NewL()
       
    53     {
       
    54     CxSPViewIdChanger* self = new (ELeave) CxSPViewIdChanger;
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop(self);
       
    58     return self;
       
    59     }
       
    60 
       
    61 void CxSPViewIdChanger::ConstructL()
       
    62     {
       
    63     // construct iTabViewNewIds from constants
       
    64     for( TInt id = EExtensionManagerTabViewStartId; id <= EExtensionManagerTabViewMaxId; id++ )
       
    65     	{
       
    66     	User::LeaveIfError( iTabViewNewIds.Append( TNewViewIdInfo( id )));
       
    67     	}
       
    68     
       
    69     // construct iNonTabViewNewIds from constants
       
    70     for( TInt id = EExtensionManagerViewStartId; id <= EExtensionManagerViewMaxId; id++ )
       
    71     	{
       
    72     	User::LeaveIfError( iNonTabViewNewIds.Append( TNewViewIdInfo( id )));
       
    73     	}
       
    74     }
       
    75 
       
    76 void CxSPViewIdChanger::ChangeViewIdsL( CArrayPtrFlat<MxSPFactory>& aFactories )
       
    77 	{
       
    78 	for( TInt i = 0; i < aFactories.Count(); i++ )
       
    79 		{
       
    80 		TInt res = aFactories[i]->ViewInfoResource();
       
    81 		if( res != KErrNotFound )
       
    82 			{
       
    83 			TResourceReader reader;
       
    84 			CCoeEnv::Static()->CreateResourceReaderLC( reader, res );
       
    85 			TInt resCount = reader.ReadInt16();
       
    86 			for( TInt j = 0; j < resCount; j++ )
       
    87 				{
       
    88 				CxSPViewInfo* viewInfo = NULL;
       
    89 				viewInfo = CxSPViewInfo::NewLC( reader, aFactories[i]->Id() );
       
    90 				User::LeaveIfError( iViewIdMap.Append( viewInfo ) );
       
    91 				CleanupStack::Pop(); // viewInfo
       
    92 				}
       
    93 			CleanupStack::PopAndDestroy(); // reader
       
    94 			aFactories[i]->RegisterViewMapper( *this );	
       
    95 			}
       
    96 		else
       
    97 			{
       
    98 			TInt viewInfoCount = aFactories[i]->ViewInfoCount();
       
    99 			for( TInt j = 0; j < viewInfoCount; j++ )
       
   100 				{
       
   101 				CxSPViewInfo* viewInfo = NULL;
       
   102 				const MxSPViewInfo* info = aFactories[i]->ViewInfo( j );
       
   103 				if( info )
       
   104 					{
       
   105 					viewInfo = CxSPViewInfo::NewLC( *info, aFactories[i]->Id() );
       
   106 					User::LeaveIfError( iViewIdMap.Append( viewInfo ) );
       
   107 					CleanupStack::Pop(); // viewInfo
       
   108 					}
       
   109 				}
       
   110 			aFactories[i]->RegisterViewMapper( *this );
       
   111 			}			
       
   112 		}
       
   113 		
       
   114 	xSPOrderOrganizer::OrderCheck( iViewIdMap );
       
   115 	
       
   116 	for( TInt i = 0; i < iViewIdMap.Count(); i++ )
       
   117 		{
       
   118 		CxSPViewInfo& viewInfo = *iViewIdMap[i];
       
   119 		if( viewInfo.TabView() )
       
   120 			{
       
   121 			User::LeaveIfError( viewInfo.SetNewId( iTabViewNewIds ) );
       
   122 			}
       
   123 		else
       
   124 			{
       
   125 			User::LeaveIfError( viewInfo.SetNewId( iNonTabViewNewIds ) );
       
   126 			}
       
   127 		}
       
   128 	}
       
   129 
       
   130 void CxSPViewIdChanger::ChangeManagerViewIdsL()
       
   131 	{
       
   132 	TInt res = R_EXTENSION_MANAGER_VIEW_INFO;
       
   133 	TResourceReader reader;
       
   134 	CCoeEnv::Static()->CreateResourceReaderLC( reader, res );
       
   135 	TInt resCount = reader.ReadInt16();
       
   136 	for( TInt j = 0; j < resCount; j++ )
       
   137 		{
       
   138 		CxSPViewInfo* viewInfo = CxSPViewInfo::NewLC( reader, KEXTENSIONMANAGERIMPLEMENTATIONUID );
       
   139 		User::LeaveIfError( viewInfo->SetNewId( iNonTabViewNewIds ) );										
       
   140 		User::LeaveIfError( iViewIdMap.Append( viewInfo ) );
       
   141 		CleanupStack::Pop(); // viewInfo
       
   142 		}
       
   143 	CleanupStack::PopAndDestroy(); // reader
       
   144 	}
       
   145 
       
   146 
       
   147 TInt CxSPViewIdChanger::GetOldView( TUint32 aId, TInt aNewView, TInt& aOldView ) const
       
   148 	{
       
   149 	TInt mapCount = iViewIdMap.Count();
       
   150 	TInt err( KErrNotFound );
       
   151 	for( TInt i = 0; i < mapCount && err; i++ )
       
   152 		{
       
   153 		CxSPViewInfo* info = iViewIdMap[i];
       
   154 		if( info->Id() == aId && info->NewViewId() == aNewView )
       
   155 			{
       
   156 			aOldView = info->OldViewId();
       
   157 			err = KErrNone;
       
   158 			}
       
   159 		}
       
   160 	return err;
       
   161 	}
       
   162 
       
   163 TInt CxSPViewIdChanger::GetNewView( TUint32 aId, TInt aOldView, TInt& aNewView ) const
       
   164 	{
       
   165 	TInt mapCount = iViewIdMap.Count();
       
   166 	TInt err( KErrNotFound );
       
   167 	for( TInt i = 0; i < mapCount && err; i++ )
       
   168 		{
       
   169 		CxSPViewInfo* info = iViewIdMap[i];
       
   170 		if( info->Id() == aId && info->OldViewId() == aOldView )
       
   171 			{
       
   172 			aNewView = info->NewViewId();
       
   173 			err = KErrNone;
       
   174 			}
       
   175 		}
       
   176 	return err;
       
   177 	}
       
   178 
       
   179 void CxSPViewIdChanger::GetViewCount( TInt &aTabs, TInt &aOthers ) const
       
   180 	{
       
   181 	aTabs = 0;
       
   182 	aOthers = 0;
       
   183 	TInt mapCount = iViewIdMap.Count();
       
   184 	for( TInt i = 0; i < mapCount; i++ )
       
   185 		{
       
   186 		CxSPViewInfo* info = iViewIdMap[i];
       
   187 		if( info->TabView() )
       
   188 			{
       
   189 			aTabs++;
       
   190 			}
       
   191 		else
       
   192 			{
       
   193 			aOthers++;
       
   194 			}
       
   195 		}
       
   196 	}
       
   197 
       
   198 void CxSPViewIdChanger::GetTabViewInfoL( TUint32 aId, 
       
   199 										 RPointerArray<CxSPViewInfo>& aInfoArray ) const
       
   200 	{
       
   201 	TInt mapCount = iViewIdMap.Count();
       
   202 	for( TInt i = 0; i < mapCount; i++ )
       
   203 		{
       
   204 		CxSPViewInfo* info = iViewIdMap[i];
       
   205 		if( info->TabView() && info->Id() == aId )
       
   206 			{
       
   207 			User::LeaveIfError( aInfoArray.Append( info ) );
       
   208 			}
       
   209 		}
       
   210 	}
       
   211 	
       
   212 void CxSPViewIdChanger::GetTabViewInfoL( RPointerArray<CxSPViewInfo>& aInfoArray ) const
       
   213 	{
       
   214 	TInt mapCount = iViewIdMap.Count();
       
   215 	for( TInt i = 0; i < mapCount; i++ )
       
   216 		{
       
   217 		CxSPViewInfo* info = iViewIdMap[i];
       
   218 		if( info->TabView() )
       
   219 			{
       
   220 			User::LeaveIfError( aInfoArray.Append( info ) );
       
   221 			}
       
   222 		}
       
   223 	}	
       
   224 
       
   225 void CxSPViewIdChanger::WriteTabViewNamesToRepositoryL()
       
   226     {
       
   227     HBufC* nameStr = HBufC::NewLC(NCentralRepositoryConstants::KMaxUnicodeStringLength);
       
   228     TPtr namePtr = nameStr->Des();
       
   229     TInt cenRepError = KErrNone;
       
   230     
       
   231     CRepository* repository = CRepository::NewLC( TUid::Uid(KCRUidPhonebook) );
       
   232         
       
   233     // delete anyway even though aError==KErrNone
       
   234     cenRepError = repository->Delete( KPhonebooksXPExtensionPluginsName ); 
       
   235     // create a new CenRep by KPhonebooksXPExtensionPluginsName
       
   236     cenRepError = repository->Create(KPhonebooksXPExtensionPluginsName, namePtr);    
       
   237     
       
   238     if ( cenRepError==KErrNone )
       
   239         {
       
   240         for( TInt i = 0; i < iViewIdMap.Count(); i++ )
       
   241             {
       
   242             CxSPViewInfo* info = iViewIdMap[i];   
       
   243             TInt len = namePtr.Length();
       
   244             TInt maxLen = namePtr.MaxLength();
       
   245             TInt viewNameLen = info->Name().Length();
       
   246             if( info && info->TabView() && viewNameLen > 0 && 
       
   247                 // use > instead of >=, one more char "|" need to be appended
       
   248                 ( maxLen - len ) > viewNameLen )
       
   249                 {
       
   250                 // append service tab view name to CenRep Key
       
   251                 namePtr.Append(info->Name());
       
   252                 namePtr.Append( '|' ); // used for seperator   
       
   253                 }
       
   254             }
       
   255         
       
   256         // set sXPExtension service tab view name string to Cenrep. 
       
   257         // this string looks like "View1Name|View2Name|View3Name|...."
       
   258         cenRepError = repository->Set( KPhonebooksXPExtensionPluginsName, namePtr );
       
   259         }
       
   260   
       
   261     CleanupStack::PopAndDestroy( repository );
       
   262     CleanupStack::PopAndDestroy( nameStr );
       
   263     }
       
   264 // end of file