secureswitools/swisistools/source/rscparser/aplapplistitem.cpp
changeset 25 98b66e4fb0be
child 50 c6e8afe0ba85
equal deleted inserted replaced
24:84a16765cd86 25:98b66e4fb0be
       
     1 // Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // aplapplistitem.cpp
       
    15 //
       
    16 /** 
       
    17 * @file aplapplistitem.cpp
       
    18 *
       
    19 * @internalComponent
       
    20 * @released
       
    21 */
       
    22 #include "aplapplistitem.h"
       
    23 #include "barsc2.h"
       
    24 #include "parse.h"
       
    25 #include "uidtype.h"
       
    26 
       
    27 //
       
    28 // class CAppLocalOpaqueDataInfo
       
    29 //
       
    30 
       
    31 //Default Constructor for class CAppLocalOpaqueDataInfo
       
    32 CAppLocalOpaqueDataInfo::CAppLocalOpaqueDataInfo()
       
    33 	: iServiceUid(0),
       
    34 	  iLocale(0),
       
    35 	  iOpaqueData(NULL)
       
    36 {
       
    37 }
       
    38 
       
    39 //Destructor for class CAppLocalOpaqueDataInfo
       
    40 CAppLocalOpaqueDataInfo::~CAppLocalOpaqueDataInfo()
       
    41 {
       
    42 	delete iOpaqueData;
       
    43 }
       
    44 
       
    45 //Constructor for class CAppLocalOpaqueDataInfo
       
    46 CAppLocalOpaqueDataInfo::CAppLocalOpaqueDataInfo(TInt aLocale, TUint32 aServiceUid, Ptr8* aOpaqueData)
       
    47 	: iLocale(aLocale),
       
    48 	  iServiceUid(aServiceUid),
       
    49 	  iOpaqueData(aOpaqueData)
       
    50 {
       
    51 	assert(iOpaqueData);
       
    52 }
       
    53 
       
    54 
       
    55 CAppLocalOpaqueDataInfo* CAppLocalOpaqueDataInfo::NewL(TInt aLocale, TUint32 aServiceUid, Ptr8* aOpaqueData)
       
    56 {
       
    57 	CAppLocalOpaqueDataInfo* self=new CAppLocalOpaqueDataInfo(aLocale, aServiceUid, aOpaqueData);
       
    58 	if(NULL==self)
       
    59 	{
       
    60 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
    61 		throw CResourceFileException(errMsg);
       
    62 	}
       
    63 
       
    64 	return self;	
       
    65 }
       
    66 
       
    67 
       
    68 Ptr8* CAppLocalOpaqueDataInfo::GetOpaqueData()
       
    69 {
       
    70 	return iOpaqueData;
       
    71 }
       
    72 
       
    73 TUint32 CAppLocalOpaqueDataInfo::GetServiceUid()
       
    74 {
       
    75 	return iServiceUid;
       
    76 }
       
    77 
       
    78 TInt CAppLocalOpaqueDataInfo::GetLocale()
       
    79 {
       
    80 	return iLocale;
       
    81 }
       
    82 
       
    83 //
       
    84 // Class CAppLocalizableInfo
       
    85 //
       
    86 CAppLocalizableInfo::~CAppLocalizableInfo()
       
    87 {
       
    88 	delete iCaption;
       
    89 	delete iShortCaption;
       
    90 	delete iGroupName;
       
    91 	delete iIconFileName;
       
    92 	if(iViewDataArray)
       
    93 		iViewDataArray->clear();
       
    94 	delete iViewDataArray;
       
    95 	delete iOpaqueData;
       
    96 }
       
    97 
       
    98 CAppLocalizableInfo::CAppLocalizableInfo(const std::string& aRegistrationFileName, const std::string& aLocalizeFilePath)
       
    99 	: iNumOfAppIcons(0),
       
   100 	iRegistrationFilePath(aRegistrationFileName),
       
   101 	iLocalPath(aLocalizeFilePath)
       
   102 {
       
   103 	iCaption = NULL;
       
   104 	iShortCaption = NULL;
       
   105 	iIconFileName = NULL;
       
   106 	iGroupName = NULL;
       
   107 	iViewDataArray = NULL;
       
   108 	iOpaqueData = NULL;
       
   109 }
       
   110 
       
   111 CAppLocalizableInfo* CAppLocalizableInfo::NewL(const std::string& aRegistrationFileName,const std::string& aLocalizeFilePath)
       
   112 {
       
   113 	CAppLocalizableInfo* self=new CAppLocalizableInfo(aRegistrationFileName, aLocalizeFilePath);
       
   114 	if(NULL==self)
       
   115 	{
       
   116 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   117 		throw CResourceFileException(errMsg);
       
   118 	}
       
   119 
       
   120 	return self;	
       
   121 }
       
   122 
       
   123 
       
   124 void CAppLocalizableInfo::SetCaption(Ptr16* Caption)
       
   125 {	
       
   126 	iCaption = Caption;
       
   127 }
       
   128 void CAppLocalizableInfo::SetShortCaption(Ptr16* ShortCaption)
       
   129 {
       
   130 	iShortCaption = ShortCaption;
       
   131 }
       
   132 void CAppLocalizableInfo::SetGroupName(Ptr16* GroupName)
       
   133 {
       
   134 	iGroupName = GroupName;
       
   135 }
       
   136 void CAppLocalizableInfo::SetIconFileName(Ptr16* IconFileName)
       
   137 {
       
   138 	iIconFileName = IconFileName;
       
   139 }
       
   140 
       
   141 void CAppLocalizableInfo::SetNumOfAppIcons(TInt NumOfAppIcons)
       
   142 {
       
   143 	iNumOfAppIcons = NumOfAppIcons;
       
   144 }
       
   145 
       
   146 void CAppLocalizableInfo::SetLocale(TInt Locale)
       
   147 {
       
   148 	iLocale = Locale;
       
   149 }
       
   150 
       
   151 void CAppLocalizableInfo::SetOpaqueData(Ptr8* OpaqueData)
       
   152 {
       
   153 	iOpaqueData = OpaqueData;
       
   154 }
       
   155 
       
   156 std::vector<CAppViewData*>* CAppLocalizableInfo::GetViewDataArray()
       
   157 {
       
   158 	return iViewDataArray;
       
   159 }
       
   160 Ptr16* CAppLocalizableInfo::GetGroupName()
       
   161 {
       
   162 	return iGroupName;
       
   163 }
       
   164 
       
   165 Ptr16* CAppLocalizableInfo::GetCaption()
       
   166 {
       
   167 	return iCaption;
       
   168 }
       
   169 
       
   170 Ptr16* CAppLocalizableInfo::GetShortCaption()
       
   171 {
       
   172 	return iShortCaption;
       
   173 }
       
   174 
       
   175 Ptr16* CAppLocalizableInfo::GetIconFileName()
       
   176 {
       
   177 	return iIconFileName;
       
   178 }
       
   179 
       
   180 TInt CAppLocalizableInfo::GetNumOfAppIcons()
       
   181 {
       
   182 	return iNumOfAppIcons;
       
   183 }
       
   184 
       
   185 TInt CAppLocalizableInfo::GetLocale()
       
   186 {
       
   187 	return iLocale;
       
   188 }	
       
   189 
       
   190 Ptr8* CAppLocalizableInfo::GetOpaqueData()
       
   191 {
       
   192 	return iOpaqueData;
       
   193 }
       
   194 
       
   195 //Read ViewData struct of Localizable resource file.
       
   196 void CAppLocalizableInfo::ReadViewDataL(RResourceReader& aResourceReader)
       
   197 {
       
   198 	// read LEN WORD STRUCT view_list[]
       
   199 	const TInt numOfViews = aResourceReader.ReadInt16L();
       
   200 
       
   201 	if (numOfViews > 0)
       
   202 	{
       
   203 		iViewDataArray = new std::vector<CAppViewData*>;
       
   204 		if(NULL==iViewDataArray)
       
   205 		{
       
   206 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   207 			throw CResourceFileException(errMsg);
       
   208 		}
       
   209 	}
       
   210 
       
   211 	for(TInt view = 0; view < numOfViews; ++view)
       
   212 	{
       
   213 		CAppViewData* viewData = CAppViewData::NewL();
       
   214 		aResourceReader.ReadUint32L(); // skip over LONG reserved_long
       
   215 		aResourceReader.ReadUint32L(); // skip over LLINK reserved_llink
       
   216 
       
   217 		// read LONG uid
       
   218 		const TUid viewUid =  {aResourceReader.ReadInt32L()};
       
   219 		viewData->SetUid(viewUid);
       
   220 		// read LONG screen_mode
       
   221 		const TInt screenMode = aResourceReader.ReadInt32L();
       
   222 		viewData->SetScreenMode(screenMode);
       
   223 
       
   224 		aResourceReader.ReadUint32L(); // skip over LONG reserved_long
       
   225 		aResourceReader.ReadUint32L(); // skip over LLINK reserved_llink
       
   226 
       
   227 		// read LTEXT caption
       
   228 		PtrC16* viewCaption = aResourceReader.ReadTPtrCL();
       
   229 		if(NULL != viewCaption)
       
   230 		{
       
   231 			viewData->SetCaptionL(viewCaption);
       
   232 
       
   233 			viewCaption->iPtr = NULL; //To Avoid double delete in destructor. To be destroyed by RResourceReader.
       
   234 			delete viewCaption;
       
   235 		}
       
   236 		// read WORD number_of_icons
       
   237 		const TInt numOfViewIcons = aResourceReader.ReadInt16L();
       
   238 		viewData->SetNumOfViewIcons(numOfViewIcons);
       
   239 
       
   240 		// read LTEXT icon_file
       
   241 		PtrC16* viewIconFile = aResourceReader.ReadTPtrCL();
       
   242 		if(NULL != viewIconFile)
       
   243 		{
       
   244 
       
   245 			Ptr16*	fullViewIconFileName = ViewDataIconFileNameL(viewIconFile);
       
   246 			if (fullViewIconFileName)
       
   247 			{
       
   248 				viewData->SetIconFileNameL(fullViewIconFileName);
       
   249 				viewData->SetNonMbmIconFile(true);
       
   250 				delete fullViewIconFileName;
       
   251 			}
       
   252 			else
       
   253 			{
       
   254 				viewIconFile->iPtr = NULL;
       
   255 				viewIconFile->iMaxLength = 0;
       
   256 
       
   257 				if (numOfViewIcons > 0 && iIconFileName)
       
   258 				{ // default to app icon filename
       
   259 					viewIconFile->iPtr = iIconFileName->GetPtr(); 
       
   260 					viewIconFile->iMaxLength = iIconFileName->GetLength();
       
   261 				std::string errMsg= "Failed : ServiceInfo Icon File not present in Device.";
       
   262 				throw CResourceFileException(errMsg);
       
   263 				}
       
   264 			}
       
   265 		}
       
   266 
       
   267 		iViewDataArray->push_back(viewData);
       
   268 		if(NULL != viewIconFile)
       
   269 		{
       
   270 			viewIconFile->iPtr = NULL; //To Avoid double delete in destructor. To be destroyed by RResourceReader.
       
   271 		}
       
   272 		delete viewIconFile;
       
   273 	}
       
   274 
       
   275 }
       
   276 
       
   277 
       
   278 Ptr16* CAppLocalizableInfo::ViewDataIconFileNameL(const PtrC16* aIconFileName) const
       
   279 {
       
   280 	Ptr16* filename = NULL;
       
   281 	if (aIconFileName->iMaxLength == 0)
       
   282 		return NULL;
       
   283 
       
   284 	/*
       
   285 	 * aIconFileName may contain a valid string in some format (for eg. URI format) other than path to a regular file on disk
       
   286 	 * and that can be a mbm or non-mbm file. Such a filename will be reported as invalid filename by iFs.IsValidName() method. 
       
   287 	 * aIconFileName will be returned since it is a valid string. 
       
   288 	 */	
       
   289 	ParsePtrC parsePtr(aIconFileName);
       
   290 	if (parsePtr.IsWild() || !parsePtr.PathPresent() || !parsePtr.NamePresent())
       
   291 		return NULL;
       
   292 
       
   293 	filename = new Ptr16(aIconFileName->iMaxLength);
       
   294 	if(NULL==filename || NULL == filename->GetPtr())
       
   295 	{
       
   296 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   297 		throw CResourceFileException(errMsg);
       
   298 	}
       
   299 	filename->UpdateLength(aIconFileName->iMaxLength);
       
   300 	BufCpy(filename->GetPtr(),aIconFileName->iPtr,aIconFileName->iMaxLength);
       
   301 
       
   302 	std::wstring iFileName = Ptr16ToWstring(filename);
       
   303 	std::wstring iFilePath = string2wstring(iLocalPath);
       
   304 	std::string fullnamewitoutdrive = parsePtr.FullNameWithoutDrive();
       
   305 	std::wstring iFilename1 = string2wstring(fullnamewitoutdrive);
       
   306 
       
   307 	if(parsePtr.DrivePresent())
       
   308 		iFilePath.append(iFilename1);
       
   309 	else
       
   310 		iFilePath.append(iFileName);
       
   311 
       
   312 	// check for fully qualified icon filename
       
   313 	if (parsePtr.DrivePresent() && FileExists(iFileName))
       
   314 	{
       
   315 		parsePtr.SetToNull();
       
   316 		return filename;	
       
   317 	}
       
   318 	else
       
   319 	{
       
   320 		// check for icon file on same drive as localisable resource file
       
   321 		std::string localisableResourceFileDrive = parsePtr.Drive();
       
   322 		TInt ret = FindWild(aIconFileName);
       
   323 		if(ret == 0 && FileExists(iFilePath))
       
   324 		{
       
   325 			parsePtr.SetToNull();
       
   326 			return filename;
       
   327 		}
       
   328 		else
       
   329 		{
       
   330 			ParsePtrC parsePtr_reg(iRegistrationFilePath);
       
   331 			std::string registrationFileDrive = parsePtr_reg.Drive();
       
   332 
       
   333 			if(registrationFileDrive.compare(localisableResourceFileDrive))
       
   334 			{
       
   335 				// check for icon file on same drive as registration file
       
   336 				std::string registrationfilepath(parsePtr_reg.FullPath());
       
   337 				registrationfilepath.append(parsePtr.NameAndExt());
       
   338 				std::wstring iRegFilePath = string2wstring(registrationfilepath);
       
   339 				std::string iconfile = parsePtr.StrName();
       
   340 			
       
   341 				ret = FindWild(registrationFileDrive,iconfile,localisableResourceFileDrive);
       
   342 				if(ret == 0 && FileExists(iRegFilePath))
       
   343 				{
       
   344 					parsePtr_reg.SetToNull();
       
   345 					parsePtr.SetToNull();
       
   346 					return filename;
       
   347 				}
       
   348 			}
       
   349 			parsePtr_reg.SetToNull();
       
   350 		}
       
   351 	}
       
   352 	parsePtr.SetToNull();	//To Avoid double delete in destructor. To be destroyed by RResourceReader.
       
   353 							//Same as iIconFileName data member of class CAppInfoReader. Destructor will delete.
       
   354 	return NULL;					// Or to be deleted by calling function.
       
   355 }
       
   356 
       
   357 //
       
   358 // Class CAppViewData
       
   359 //
       
   360 
       
   361 CAppViewData::~CAppViewData()
       
   362 {
       
   363 	delete iCaption;
       
   364 	delete iIconFileName;
       
   365 }
       
   366 
       
   367 CAppViewData::CAppViewData()
       
   368 	: iNonMbmIconFile(false),iNumOfViewIcons(0),iScreenMode(0)
       
   369 {
       
   370 	iCaption = NULL;
       
   371 	iIconFileName = NULL;
       
   372 	iUid = NullUid;
       
   373 }
       
   374 
       
   375 CAppViewData* CAppViewData::NewL()
       
   376 {
       
   377 	CAppViewData* self=new CAppViewData();
       
   378 	if(NULL==self)
       
   379 	{
       
   380 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   381 		throw CResourceFileException(errMsg);
       
   382 	}
       
   383 
       
   384 	return self;	
       
   385 }
       
   386 
       
   387 void CAppViewData::SetUid(TUid aUid)
       
   388 {
       
   389 	iUid=aUid;
       
   390 }
       
   391 
       
   392 void CAppViewData::SetScreenMode(TInt aScreenMode)
       
   393 {
       
   394 	iScreenMode=aScreenMode;
       
   395 }
       
   396 
       
   397 void CAppViewData::SetCaptionL(const PtrC16* aCaption)
       
   398 {
       
   399 	if(aCaption != NULL)
       
   400 	{
       
   401 		iCaption=new Ptr16(aCaption->iMaxLength);
       
   402 		if(NULL==iCaption || NULL==iCaption->GetPtr())
       
   403 		{
       
   404 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   405 			throw CResourceFileException(errMsg);
       
   406 		}
       
   407 		iCaption->UpdateLength(aCaption->iMaxLength);
       
   408 		BufCpy(iCaption->GetPtr(),aCaption->iPtr,aCaption->iMaxLength);
       
   409 	}
       
   410 	else
       
   411 		iCaption = NULL;
       
   412 }
       
   413 
       
   414 void CAppViewData::SetIconFileNameL(const Ptr16* aFileName)
       
   415 {
       
   416 	if(aFileName != NULL)
       
   417 	{
       
   418 		iIconFileName = new Ptr16(aFileName->GetLength());
       
   419 		if(NULL==iIconFileName || NULL==iIconFileName->GetPtr())
       
   420 		{
       
   421 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   422 			throw CResourceFileException(errMsg);
       
   423 		}
       
   424 		iIconFileName->UpdateLength(aFileName->GetLength());
       
   425 		BufCpy(iIconFileName->GetPtr(),aFileName->GetPtr(),aFileName->GetLength());
       
   426 	}
       
   427 	else
       
   428 		iIconFileName = NULL;
       
   429 }
       
   430 
       
   431 void CAppViewData::SetNumOfViewIcons(TInt aNumOfViewIcons)
       
   432 {
       
   433 	iNumOfViewIcons = aNumOfViewIcons;
       
   434 }
       
   435 
       
   436 void CAppViewData::SetNonMbmIconFile(TBool aNonMbmIconFile)
       
   437 {
       
   438 	iNonMbmIconFile = aNonMbmIconFile;
       
   439 }
       
   440 
       
   441 TUid CAppViewData::Uid() const
       
   442 {
       
   443 	return iUid;
       
   444 }
       
   445 
       
   446 Ptr16* CAppViewData::GetCaption()
       
   447 {
       
   448 	return iCaption;
       
   449 }
       
   450 TInt CAppViewData::GetScreenMode()
       
   451 {
       
   452 	return iScreenMode;
       
   453 }
       
   454 Ptr16* CAppViewData::GetIconFileName()
       
   455 {
       
   456 	return iIconFileName;
       
   457 }
       
   458 TInt CAppViewData::GetNumOfViewIcons()
       
   459 {
       
   460 	return iNumOfViewIcons;
       
   461 }