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 |
|
230 if(NULL != viewCaption) |
|
231 { |
|
232 viewData->SetCaptionL(viewCaption); |
|
233 |
|
234 viewCaption->iPtr = NULL; //To Avoid double delete in destructor. To be destroyed by RResourceReader. |
|
235 delete viewCaption; |
|
236 } |
|
237 // read WORD number_of_icons |
|
238 const TInt numOfViewIcons = aResourceReader.ReadInt16L(); |
|
239 viewData->SetNumOfViewIcons(numOfViewIcons); |
|
240 |
|
241 // read LTEXT icon_file |
|
242 PtrC16* viewIconFile = aResourceReader.ReadTPtrCL(); |
|
243 |
|
244 if(NULL != viewIconFile) |
|
245 { |
|
246 ConvertToPlatformSpecificPath(viewIconFile->iPtr, viewIconFile->iMaxLength); |
|
247 Ptr16* fullViewIconFileName = ViewDataIconFileNameL(viewIconFile); |
|
248 if (fullViewIconFileName) |
|
249 { |
|
250 viewData->SetIconFileNameL(fullViewIconFileName); |
|
251 viewData->SetNonMbmIconFile(true); |
|
252 delete fullViewIconFileName; |
|
253 } |
|
254 else |
|
255 { |
|
256 viewIconFile->iPtr = NULL; |
|
257 viewIconFile->iMaxLength = 0; |
|
258 |
|
259 if (numOfViewIcons > 0 && iIconFileName) |
|
260 { // default to app icon filename |
|
261 viewIconFile->iPtr = iIconFileName->GetPtr(); |
|
262 viewIconFile->iMaxLength = iIconFileName->GetLength(); |
|
263 std::string errMsg= "Failed : ServiceInfo Icon File not present in Device."; |
|
264 throw CResourceFileException(errMsg); |
|
265 } |
|
266 } |
|
267 } |
|
268 |
|
269 iViewDataArray->push_back(viewData); |
|
270 if(NULL != viewIconFile) |
|
271 { |
|
272 viewIconFile->iPtr = NULL; //To Avoid double delete in destructor. To be destroyed by RResourceReader. |
|
273 } |
|
274 delete viewIconFile; |
|
275 } |
|
276 |
|
277 } |
|
278 |
|
279 |
|
280 Ptr16* CAppLocalizableInfo::ViewDataIconFileNameL(const PtrC16* aIconFileName) const |
|
281 { |
|
282 Ptr16* filename = NULL; |
|
283 if (aIconFileName->iMaxLength == 0) |
|
284 return NULL; |
|
285 |
|
286 /* |
|
287 * aIconFileName may contain a valid string in some format (for eg. URI format) other than path to a regular file on disk |
|
288 * and that can be a mbm or non-mbm file. Such a filename will be reported as invalid filename by iFs.IsValidName() method. |
|
289 * aIconFileName will be returned since it is a valid string. |
|
290 */ |
|
291 ParsePtrC parsePtr(aIconFileName); |
|
292 |
|
293 if ( parsePtr.IsWild() || !parsePtr.PathPresent() || !parsePtr.NamePresent() ) |
|
294 { |
|
295 parsePtr.SetToNull(); |
|
296 return NULL; |
|
297 } |
|
298 |
|
299 filename = new Ptr16(aIconFileName->iMaxLength); |
|
300 if(NULL==filename || NULL == filename->GetPtr()) |
|
301 { |
|
302 parsePtr.SetToNull(); |
|
303 std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed"; |
|
304 throw CResourceFileException(errMsg); |
|
305 } |
|
306 filename->UpdateLength(aIconFileName->iMaxLength); |
|
307 BufCpy(filename->GetPtr(),aIconFileName->iPtr,aIconFileName->iMaxLength); |
|
308 |
|
309 std::wstring iFileName = Ptr16ToWstring(filename); |
|
310 std::wstring iFilePath = string2wstring(iLocalPath); |
|
311 std::string fullnamewitoutdrive = parsePtr.FullNameWithoutDrive(); |
|
312 std::wstring iFilename1 = string2wstring(fullnamewitoutdrive); |
|
313 |
|
314 if(parsePtr.DrivePresent()) |
|
315 iFilePath.append(iFilename1); |
|
316 else |
|
317 iFilePath.append(iFileName); |
|
318 |
|
319 // check for fully qualified icon filename |
|
320 if (parsePtr.DrivePresent() && FileExists(iFileName)) |
|
321 { |
|
322 parsePtr.SetToNull(); |
|
323 return filename; |
|
324 } |
|
325 else |
|
326 { |
|
327 // check for icon file on same drive as localisable resource file |
|
328 std::string localisableResourceFileDrive = parsePtr.Drive(); |
|
329 TInt ret = FindWild(aIconFileName); |
|
330 if(ret == 0 && FileExists(iFilePath)) |
|
331 { |
|
332 parsePtr.SetToNull(); |
|
333 return filename; |
|
334 } |
|
335 else |
|
336 { |
|
337 ParsePtrC parsePtr_reg(iRegistrationFilePath); |
|
338 std::string registrationFileDrive = parsePtr_reg.Drive(); |
|
339 |
|
340 if(registrationFileDrive.compare(localisableResourceFileDrive)) |
|
341 { |
|
342 // check for icon file on same drive as registration file |
|
343 std::string registrationfilepath(parsePtr_reg.FullPath()); |
|
344 registrationfilepath.append(parsePtr.NameAndExt()); |
|
345 std::wstring iRegFilePath = string2wstring(registrationfilepath); |
|
346 std::string iconfile = parsePtr.StrName(); |
|
347 |
|
348 ret = FindWild(registrationFileDrive,iconfile,localisableResourceFileDrive); |
|
349 if(ret == 0 && FileExists(iRegFilePath)) |
|
350 { |
|
351 parsePtr_reg.SetToNull(); |
|
352 parsePtr.SetToNull(); |
|
353 return filename; |
|
354 } |
|
355 } |
|
356 parsePtr_reg.SetToNull(); |
|
357 } |
|
358 } |
|
359 parsePtr.SetToNull(); //To Avoid double delete in destructor. To be destroyed by RResourceReader. |
|
360 //Same as iIconFileName data member of class CAppInfoReader. Destructor will delete. |
|
361 return NULL; // Or to be deleted by calling function. |
|
362 } |
|
363 |
|
364 // |
|
365 // Class CAppViewData |
|
366 // |
|
367 |
|
368 CAppViewData::~CAppViewData() |
|
369 { |
|
370 delete iCaption; |
|
371 delete iIconFileName; |
|
372 } |
|
373 |
|
374 CAppViewData::CAppViewData() |
|
375 : iNonMbmIconFile(false),iNumOfViewIcons(0),iScreenMode(0) |
|
376 { |
|
377 iCaption = NULL; |
|
378 iIconFileName = NULL; |
|
379 iUid = NullUid; |
|
380 } |
|
381 |
|
382 CAppViewData* CAppViewData::NewL() |
|
383 { |
|
384 CAppViewData* self=new CAppViewData(); |
|
385 if(NULL==self) |
|
386 { |
|
387 std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed"; |
|
388 throw CResourceFileException(errMsg); |
|
389 } |
|
390 |
|
391 return self; |
|
392 } |
|
393 |
|
394 void CAppViewData::SetUid(TUid aUid) |
|
395 { |
|
396 iUid=aUid; |
|
397 } |
|
398 |
|
399 void CAppViewData::SetScreenMode(TInt aScreenMode) |
|
400 { |
|
401 iScreenMode=aScreenMode; |
|
402 } |
|
403 |
|
404 void CAppViewData::SetCaptionL(const PtrC16* aCaption) |
|
405 { |
|
406 if(aCaption != NULL) |
|
407 { |
|
408 iCaption=new Ptr16(aCaption->iMaxLength); |
|
409 if(NULL==iCaption || NULL==iCaption->GetPtr()) |
|
410 { |
|
411 std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed"; |
|
412 throw CResourceFileException(errMsg); |
|
413 } |
|
414 iCaption->UpdateLength(aCaption->iMaxLength); |
|
415 BufCpy(iCaption->GetPtr(),aCaption->iPtr,aCaption->iMaxLength); |
|
416 } |
|
417 else |
|
418 iCaption = NULL; |
|
419 } |
|
420 |
|
421 void CAppViewData::SetIconFileNameL(const Ptr16* aFileName) |
|
422 { |
|
423 if(aFileName != NULL) |
|
424 { |
|
425 iIconFileName = new Ptr16(aFileName->GetLength()); |
|
426 if(NULL==iIconFileName || NULL==iIconFileName->GetPtr()) |
|
427 { |
|
428 std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed"; |
|
429 throw CResourceFileException(errMsg); |
|
430 } |
|
431 iIconFileName->UpdateLength(aFileName->GetLength()); |
|
432 BufCpy(iIconFileName->GetPtr(),aFileName->GetPtr(),aFileName->GetLength()); |
|
433 } |
|
434 else |
|
435 iIconFileName = NULL; |
|
436 } |
|
437 |
|
438 void CAppViewData::SetNumOfViewIcons(TInt aNumOfViewIcons) |
|
439 { |
|
440 iNumOfViewIcons = aNumOfViewIcons; |
|
441 } |
|
442 |
|
443 void CAppViewData::SetNonMbmIconFile(TBool aNonMbmIconFile) |
|
444 { |
|
445 iNonMbmIconFile = aNonMbmIconFile; |
|
446 } |
|
447 |
|
448 TUid CAppViewData::Uid() const |
|
449 { |
|
450 return iUid; |
|
451 } |
|
452 |
|
453 Ptr16* CAppViewData::GetCaption() |
|
454 { |
|
455 return iCaption; |
|
456 } |
|
457 TInt CAppViewData::GetScreenMode() |
|
458 { |
|
459 return iScreenMode; |
|
460 } |
|
461 Ptr16* CAppViewData::GetIconFileName() |
|
462 { |
|
463 return iIconFileName; |
|
464 } |
|
465 TInt CAppViewData::GetNumOfViewIcons() |
|
466 { |
|
467 return iNumOfViewIcons; |
|
468 } |
|