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