|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <driveinfo.h> |
|
22 #include <xmlengnodelist.h> |
|
23 #include <xmlengdomparser.h> |
|
24 #include <xmlengdocument.h> |
|
25 #include <UTF.H> |
|
26 |
|
27 #include "cawidgetscannerparser.h" |
|
28 #include "widgetscannerutils.h" |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 const TInt KChunkSize = 8192; |
|
33 const TInt KDriveLetterLength = 2; |
|
34 |
|
35 _LIT( KManifest, ".manifest"); |
|
36 _LIT( KColen, ":" ); |
|
37 _LIT( KImportDir, "\\private\\20022F35\\import\\widgetregistry\\" ); |
|
38 //_LIT( KImportDir, "import\\widgetregistry\\" ); |
|
39 _LIT( KDoubleSlash, "\\" ); |
|
40 _LIT( KTrue, "true" ); |
|
41 _LIT8(KWidget, "widget" ); |
|
42 _LIT8(KUri, "uri" ); |
|
43 _LIT8(KLibrary, "library" ); |
|
44 _LIT8(KTitle, "title" ); |
|
45 _LIT8(KDescription, "description" ); |
|
46 _LIT8(KHidden, "hidden" ); |
|
47 _LIT8(KIconUri, "iconuri" ); |
|
48 |
|
49 |
|
50 // ============================ MEMBER FUNCTIONS =============================== |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CCaWidgetScannerParser::CCaWidgetScannerParser |
|
54 // C++ default constructor can NOT contain any code, that |
|
55 // might leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CCaWidgetScannerParser::CCaWidgetScannerParser( RFs& aFs ): |
|
59 iFs( aFs ) |
|
60 { |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CCaWidgetScannerParser::ConstructL |
|
65 // Symbian 2nd phase constructor can leave. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CCaWidgetScannerParser::ConstructL( ) |
|
69 { |
|
70 iImportPath.CreateL( KMaxPath ); |
|
71 //iFs.PrivatePath( iImportPath ); |
|
72 iImportPath.Append( KImportDir ); |
|
73 iDomImpl.OpenL(); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CCaWidgetScannerParser::NewL |
|
78 // Two-phased constructor. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CCaWidgetScannerParser* CCaWidgetScannerParser::NewL( RFs& aFs ) |
|
82 { |
|
83 CCaWidgetScannerParser* self = NewLC( aFs ); |
|
84 CleanupStack::Pop( self ); |
|
85 return self; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CCaWidgetScannerParser::NewLC |
|
90 // Two-phased constructor. |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CCaWidgetScannerParser* CCaWidgetScannerParser::NewLC( RFs& aFs ) |
|
94 { |
|
95 CCaWidgetScannerParser* self = new( ELeave ) CCaWidgetScannerParser( aFs ); |
|
96 CleanupStack::PushL( self ); |
|
97 self->ConstructL( ); |
|
98 return self; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // Destructor |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CCaWidgetScannerParser::~CCaWidgetScannerParser() |
|
106 { |
|
107 iImportPath.Close(); |
|
108 iWidgets.ResetAndDestroy(); |
|
109 iDomImpl.Close(); |
|
110 } |
|
111 |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 // ---------------------------------------------------------------------------- |
|
115 // |
|
116 RWidgetArray& CCaWidgetScannerParser::WidgetsScanL( ) |
|
117 { |
|
118 TDriveList driveList; |
|
119 User::LeaveIfError( iFs.DriveList( driveList ) ); |
|
120 iWidgets.ResetAndDestroy(); |
|
121 |
|
122 for ( TInt driveNumber=EDriveZ; driveNumber >= EDriveA; driveNumber-- ) |
|
123 { |
|
124 if ( driveList[driveNumber] ) |
|
125 { |
|
126 User::LeaveIfError( iFs.DriveToChar( driveNumber, |
|
127 iCurrentDriveLetter ) ); |
|
128 ScanOnDriveL( ); |
|
129 } |
|
130 } |
|
131 return iWidgets; |
|
132 } |
|
133 |
|
134 |
|
135 // ---------------------------------------------------------------------------- |
|
136 // |
|
137 // ---------------------------------------------------------------------------- |
|
138 // |
|
139 void CCaWidgetScannerParser::ScanOnDriveL( ) |
|
140 { |
|
141 CDir* directories = GetDirectoriesLC( ); |
|
142 if ( directories ) |
|
143 { |
|
144 for ( TInt i(0); i<directories->Count( ); i++ ) |
|
145 { |
|
146 if((*directories)[i].IsDir()) |
|
147 { |
|
148 ParseDirectoryL((*directories)[i].iName); |
|
149 } |
|
150 } |
|
151 } |
|
152 CleanupStack::PopAndDestroy( directories ); |
|
153 } |
|
154 |
|
155 // ---------------------------------------------------------------------------- |
|
156 // |
|
157 // ---------------------------------------------------------------------------- |
|
158 // |
|
159 void CCaWidgetScannerParser::ParseDirectoryL( const TDesC& aDirectoryName ) |
|
160 { |
|
161 HBufC* manifestDirectoryPath = |
|
162 GetManifestDirectoryPathLC( aDirectoryName ); |
|
163 |
|
164 CDir* fileList = NULL; |
|
165 |
|
166 User::LeaveIfError( iFs.GetDir( *manifestDirectoryPath, |
|
167 KEntryAttMatchExclude|KEntryAttDir, |
|
168 ESortByDate, fileList ) ); |
|
169 CleanupStack::PushL( fileList ); |
|
170 |
|
171 for ( TInt i = 0; i<fileList->Count( ); i++ ) |
|
172 { |
|
173 if( (*fileList)[i].iName.Find( KManifest ) != KErrNotFound ) |
|
174 { |
|
175 RBuf fullFilePath; |
|
176 CleanupClosePushL( fullFilePath ); |
|
177 fullFilePath.CreateL( manifestDirectoryPath->Length() + |
|
178 (*fileList)[i].iName.Length()); |
|
179 fullFilePath.Append( *manifestDirectoryPath ); |
|
180 fullFilePath.Append( (*fileList)[i].iName ); |
|
181 //if file is corrupted we go to the next one |
|
182 TRAP_IGNORE(ParseManifestFileL( fullFilePath, aDirectoryName )); |
|
183 CleanupStack::PopAndDestroy( &fullFilePath ); |
|
184 } |
|
185 } |
|
186 CleanupStack::PopAndDestroy( fileList ); |
|
187 CleanupStack::PopAndDestroy( manifestDirectoryPath ); |
|
188 } |
|
189 |
|
190 // ---------------------------------------------------------------------------- |
|
191 // |
|
192 // ---------------------------------------------------------------------------- |
|
193 // |
|
194 void CCaWidgetScannerParser::ParseManifestFileL( |
|
195 const TDesC& aFilePath, const TDesC& aPackageUid ) |
|
196 { |
|
197 RXmlEngDOMParser parser; |
|
198 CleanupClosePushL(parser); |
|
199 User::LeaveIfError(parser.Open(iDomImpl)); |
|
200 RXmlEngDocument doc = parser.ParseFileL(aFilePath, KChunkSize); |
|
201 CleanupClosePushL(doc); |
|
202 TXmlEngElement docElement = doc.AsElement(); |
|
203 TXmlEngElement element; |
|
204 RXmlEngNodeList<TXmlEngElement> elementList; |
|
205 CleanupClosePushL(elementList); |
|
206 |
|
207 element = docElement.FirstChild().AsElement(); |
|
208 element.GetElementsByTagNameL(elementList, KWidget); |
|
209 |
|
210 while (elementList.HasNext()) |
|
211 { |
|
212 element = elementList.Next(); |
|
213 if ( element.HasAttributes() ) |
|
214 { |
|
215 ParseWidgetL( element, aPackageUid ); |
|
216 } |
|
217 } |
|
218 CleanupStack::PopAndDestroy(&elementList); |
|
219 CleanupStack::PopAndDestroy(&doc); |
|
220 CleanupStack::PopAndDestroy(&parser); |
|
221 } |
|
222 |
|
223 // ---------------------------------------------------------------------------- |
|
224 // |
|
225 // ---------------------------------------------------------------------------- |
|
226 // |
|
227 void CCaWidgetScannerParser::ParseWidgetL( |
|
228 TXmlEngElement aElement, const TDesC& aPackageUid ) |
|
229 { |
|
230 CCaWidgetDescription* widget = CCaWidgetDescription::NewLC(); |
|
231 |
|
232 SetUriL( aElement, widget ); |
|
233 SetLibraryL( aElement, aPackageUid, widget); |
|
234 SetTitleL( aElement, widget ); |
|
235 SetDescriptionL( aElement, widget ); |
|
236 SetVisibilityL( aElement, widget ); |
|
237 SetIconUriL( aElement, aPackageUid, widget); |
|
238 widget->SetPackageUidL( aPackageUid ); |
|
239 SetMmcIdL( widget); |
|
240 |
|
241 TInt index = iWidgets.Find( widget, CCaWidgetDescription::Compare ); |
|
242 if ( index != KErrNotFound ) |
|
243 { |
|
244 delete iWidgets[index]; |
|
245 iWidgets.Remove( index ); |
|
246 } |
|
247 iWidgets.AppendL( widget );//ownership transfer |
|
248 CleanupStack::Pop( widget ); |
|
249 } |
|
250 |
|
251 |
|
252 // ---------------------------------------------------------------------------- |
|
253 // |
|
254 // ---------------------------------------------------------------------------- |
|
255 // |
|
256 void CCaWidgetScannerParser::SetUriL( |
|
257 TXmlEngElement & aElement, CCaWidgetDescription * aWidget ) |
|
258 { |
|
259 HBufC *attributeValue = CnvUtfConverter::ConvertToUnicodeFromUtf7L( |
|
260 aElement.AttributeValueL( KUri ) ); |
|
261 CleanupStack::PushL( attributeValue ); |
|
262 |
|
263 if( attributeValue->Compare( KNullDesC ) != 0 ) |
|
264 { |
|
265 aWidget->SetUriL( *attributeValue ); |
|
266 } |
|
267 CleanupStack::PopAndDestroy( attributeValue ); |
|
268 } |
|
269 |
|
270 // ---------------------------------------------------------------------------- |
|
271 // |
|
272 // ---------------------------------------------------------------------------- |
|
273 // |
|
274 void CCaWidgetScannerParser::SetLibraryL( TXmlEngElement & aElement, |
|
275 const TDesC & aPackageUid, CCaWidgetDescription * aWidget ) |
|
276 { |
|
277 HBufC *attributeValue = CnvUtfConverter::ConvertToUnicodeFromUtf7L( |
|
278 aElement.AttributeValueL( KLibrary ) ); |
|
279 CleanupStack::PushL( attributeValue ); |
|
280 |
|
281 if( attributeValue->Compare( KNullDesC ) != 0 ) |
|
282 { |
|
283 HBufC *libraryPath = GetManifestDirectoryPathLC( aPackageUid ); |
|
284 libraryPath->ReAllocL( |
|
285 libraryPath->Length() + attributeValue->Length()); |
|
286 |
|
287 TPtr libraryPathModifier( libraryPath->Des() ); |
|
288 libraryPathModifier.Append( *attributeValue ); |
|
289 aWidget->SetLibraryL( *libraryPath ); |
|
290 |
|
291 CleanupStack::PopAndDestroy( libraryPath ); |
|
292 } |
|
293 else |
|
294 { |
|
295 aWidget->SetLibraryL( KNoLibrary ); |
|
296 } |
|
297 CleanupStack::PopAndDestroy( attributeValue ); |
|
298 } |
|
299 |
|
300 // ---------------------------------------------------------------------------- |
|
301 // |
|
302 // ---------------------------------------------------------------------------- |
|
303 // |
|
304 void CCaWidgetScannerParser::SetTitleL( |
|
305 TXmlEngElement & aElement, CCaWidgetDescription * aWidget ) |
|
306 { |
|
307 HBufC *attributeValue = CnvUtfConverter::ConvertToUnicodeFromUtf7L( |
|
308 aElement.AttributeValueL( KTitle ) ); |
|
309 CleanupStack::PushL( attributeValue ); |
|
310 |
|
311 if( attributeValue->Compare( KNullDesC ) != 0 ) |
|
312 { |
|
313 aWidget->SetTitleL( *attributeValue ); |
|
314 } |
|
315 CleanupStack::PopAndDestroy( attributeValue ); |
|
316 } |
|
317 |
|
318 // ---------------------------------------------------------------------------- |
|
319 // |
|
320 // ---------------------------------------------------------------------------- |
|
321 // |
|
322 void CCaWidgetScannerParser::SetDescriptionL( |
|
323 TXmlEngElement & aElement, CCaWidgetDescription * aWidget ) |
|
324 { |
|
325 HBufC *attributeValue = CnvUtfConverter::ConvertToUnicodeFromUtf7L( |
|
326 aElement.AttributeValueL( KDescription ) ); |
|
327 CleanupStack::PushL( attributeValue ); |
|
328 |
|
329 if( attributeValue->Compare( KNullDesC ) != 0 ) |
|
330 { |
|
331 aWidget->SetDescriptionL( *attributeValue ); |
|
332 } |
|
333 CleanupStack::PopAndDestroy( attributeValue ); |
|
334 } |
|
335 |
|
336 // ---------------------------------------------------------------------------- |
|
337 // |
|
338 // ---------------------------------------------------------------------------- |
|
339 // |
|
340 void CCaWidgetScannerParser::SetVisibilityL( |
|
341 TXmlEngElement & aElement, CCaWidgetDescription * aWidget ) |
|
342 { |
|
343 HBufC *hidden = CnvUtfConverter::ConvertToUnicodeFromUtf7L( |
|
344 aElement.AttributeValueL( KHidden ) ); |
|
345 CleanupStack::PushL( hidden ); |
|
346 |
|
347 if( hidden->Compare( KTrue ) == 0 ) |
|
348 { |
|
349 aWidget->SetVisible( EFalse ); |
|
350 } |
|
351 CleanupStack::PopAndDestroy( hidden ); |
|
352 } |
|
353 |
|
354 // ---------------------------------------------------------------------------- |
|
355 // |
|
356 // ---------------------------------------------------------------------------- |
|
357 // |
|
358 void CCaWidgetScannerParser::SetIconUriL( TXmlEngElement & aElement, |
|
359 const TDesC & aPackageUid, CCaWidgetDescription * aWidget ) |
|
360 { |
|
361 HBufC *attributeValue = CnvUtfConverter::ConvertToUnicodeFromUtf7L( |
|
362 aElement.AttributeValueL( KIconUri ) ); |
|
363 CleanupStack::PushL( attributeValue ); |
|
364 |
|
365 if( attributeValue->Compare( KNullDesC ) != 0 ) |
|
366 { |
|
367 HBufC* iconUriPath = GetManifestDirectoryPathLC( aPackageUid ); |
|
368 iconUriPath->ReAllocL( |
|
369 iconUriPath->Length() + attributeValue->Length() ); |
|
370 |
|
371 TPtr iconUriPathModifier( iconUriPath->Des() ); |
|
372 iconUriPathModifier.Append( *attributeValue ); |
|
373 aWidget->SetIconUriL( *iconUriPath ); |
|
374 |
|
375 CleanupStack::PopAndDestroy( iconUriPath ); |
|
376 } |
|
377 CleanupStack::PopAndDestroy( attributeValue ); |
|
378 } |
|
379 |
|
380 // ---------------------------------------------------------------------------- |
|
381 // |
|
382 // ---------------------------------------------------------------------------- |
|
383 // |
|
384 void CCaWidgetScannerParser::SetMmcIdL( CCaWidgetDescription * widget ) |
|
385 { |
|
386 TChar removableDrive; |
|
387 User::LeaveIfError( DriveInfo::GetDefaultDrive( |
|
388 DriveInfo::EDefaultRemovableMassStorage, removableDrive ) ); |
|
389 |
|
390 if( iCurrentDriveLetter == removableDrive ) |
|
391 { |
|
392 widget->SetMmcId( WidgetScannerUtils::CurrentMmcId( iFs ) ); |
|
393 } |
|
394 } |
|
395 |
|
396 // ---------------------------------------------------------------------------- |
|
397 // |
|
398 // ---------------------------------------------------------------------------- |
|
399 // |
|
400 CDir* CCaWidgetScannerParser::GetDirectoriesLC( ) |
|
401 { |
|
402 CDir* result = NULL; |
|
403 HBufC* path = FullPathLC( ); |
|
404 iFs.GetDir( *path, KEntryAttDir, ESortByName, result ); |
|
405 CleanupStack::PopAndDestroy( path ); |
|
406 CleanupStack::PushL( result ); |
|
407 return result; |
|
408 } |
|
409 |
|
410 // ---------------------------------------------------------------------------- |
|
411 // |
|
412 // ---------------------------------------------------------------------------- |
|
413 // |
|
414 HBufC* CCaWidgetScannerParser::FullPathLC( ) |
|
415 { |
|
416 HBufC* result = HBufC16::NewLC( iImportPath.Length() + KDriveLetterLength ); |
|
417 TPtr modifier( result->Des() ); |
|
418 modifier.Append( iCurrentDriveLetter ); |
|
419 modifier.Append( KColen ); |
|
420 modifier.Append( iImportPath ); |
|
421 return result; |
|
422 } |
|
423 |
|
424 // ---------------------------------------------------------------------------- |
|
425 // |
|
426 // ---------------------------------------------------------------------------- |
|
427 // |
|
428 HBufC* CCaWidgetScannerParser::GetManifestDirectoryPathLC( |
|
429 const TDesC& aDirectoryName ) |
|
430 { |
|
431 HBufC* result = HBufC16::NewLC( KMaxPath ); |
|
432 TPtr modifier( result->Des() ); |
|
433 HBufC* path = FullPathLC( ); |
|
434 modifier.Append( *path ); |
|
435 CleanupStack::PopAndDestroy( path ); |
|
436 modifier.Append( aDirectoryName ); |
|
437 modifier.Append( KDoubleSlash ); |
|
438 return result; |
|
439 } |
|
440 |
|
441 // End of File |