30
|
1 |
/*
|
|
2 |
* Copyright (c) 2006-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: Plugin for file names search
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
#include <e32cmn.h>
|
|
21 |
#include <e32def.h>
|
|
22 |
#include <data_caging_path_literals.hrh>
|
|
23 |
#include <bautils.h>
|
|
24 |
#include <utf.h>
|
|
25 |
#include <barsc.h>
|
|
26 |
#include <avkon.rsg>
|
|
27 |
#include <StringLoader.h>
|
|
28 |
|
|
29 |
#include <searchtextsearcher.h>
|
|
30 |
#include <searchdocumentid.h>
|
|
31 |
#include <searchlightresult.h>
|
|
32 |
#include <searchresult.h>
|
|
33 |
#include <searchcommon.h>
|
|
34 |
#include <filessearchresource.rsg>
|
|
35 |
#include <searchpluginobserver.h>
|
|
36 |
|
|
37 |
#include "filessearcher.h"
|
|
38 |
#include "filessearchplugindefines.h"
|
|
39 |
|
|
40 |
_LIT ( KSkipPrivate, "private" );
|
|
41 |
_LIT ( KSkipSys, "sys" );
|
|
42 |
_LIT ( KSkipRta, "Z:\\rta" );
|
|
43 |
_LIT ( KSkipSystem, "System" );
|
|
44 |
_LIT ( KSkipTef, "tef_centralrepository" );
|
|
45 |
_LIT ( KSkipSysTest, "Z:\\test" );
|
|
46 |
_LIT ( KSkipSmokeTest, "Z:\\smoketest" );
|
|
47 |
_LIT ( KSkipResource, "resource" );
|
|
48 |
_LIT ( KSkipResourceDir, "Z:\\resource_files_dir" );
|
|
49 |
_LIT ( KSkipNokia, "Z:\\Nokia" );
|
|
50 |
_LIT ( KSkipCNokia, "C:\\Nokia" );
|
|
51 |
_LIT ( KSkipCDrive, "C:\\" );
|
|
52 |
_LIT ( KSkipCDriveTFW, "C:\\TestFramework" );
|
|
53 |
_LIT ( KSkipCDrivePredic, "C:\\Predic" );
|
|
54 |
_LIT ( KSkipCDriveLogs, "C:\\logs" );
|
|
55 |
|
|
56 |
const TInt constant_MB = 1024*1024;
|
|
57 |
const TInt constant_KB = 1024;
|
|
58 |
|
|
59 |
|
|
60 |
// ---------------------------------------------------------------------------------
|
|
61 |
// CFilesSearcher::NewL()
|
|
62 |
// 1st phase constructor
|
|
63 |
// ---------------------------------------------------------------------------------
|
|
64 |
//
|
|
65 |
CFilesSearcher* CFilesSearcher::NewL( const RArray<TUid>& aContentIdArray,
|
|
66 |
const CSearchCondition& aCondition,
|
|
67 |
const TUid& aPluginId,
|
|
68 |
MSearchPluginObserver& aObserver )
|
|
69 |
{
|
|
70 |
CFilesSearcher* self = new ( ELeave ) CFilesSearcher( aPluginId );
|
|
71 |
CleanupStack::PushL( self );
|
|
72 |
self->ConstructL( aContentIdArray, aCondition,aObserver );
|
|
73 |
CleanupStack::Pop( self );
|
|
74 |
|
|
75 |
return self;
|
|
76 |
}
|
|
77 |
|
|
78 |
// ---------------------------------------------------------------------------------
|
|
79 |
// CFilesSearcher::~CFilesSearcher()
|
|
80 |
// Destructor
|
|
81 |
// ---------------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
CFilesSearcher::~CFilesSearcher()
|
|
84 |
{
|
|
85 |
|
|
86 |
if ( iTextSearcher )
|
|
87 |
{
|
|
88 |
delete iTextSearcher;
|
|
89 |
iTextSearcher = NULL;
|
|
90 |
}
|
|
91 |
if ( iSizeKB )
|
|
92 |
{
|
|
93 |
|
|
94 |
delete iSizeKB;
|
|
95 |
iSizeKB = NULL;
|
|
96 |
}
|
|
97 |
if ( iSizeB )
|
|
98 |
{
|
|
99 |
|
|
100 |
delete iSizeB;
|
|
101 |
iSizeB = NULL;
|
|
102 |
}
|
|
103 |
if ( iSizeMB )
|
|
104 |
{
|
|
105 |
|
|
106 |
delete iSizeMB;
|
|
107 |
iSizeMB = NULL;
|
|
108 |
}
|
|
109 |
if(0 < iHeavyResultsArray.Count())
|
|
110 |
{
|
|
111 |
iHeavyResultsArray.ResetAndDestroy();
|
|
112 |
}
|
|
113 |
if( 0 < iCompleteFilePathArray.Count() )
|
|
114 |
iCompleteFilePathArray.ResetAndDestroy();
|
|
115 |
}
|
|
116 |
|
|
117 |
|
|
118 |
// ---------------------------------------------------------------------------
|
|
119 |
// Gets the complete file path of the item in the iCompleteFilePathArray
|
|
120 |
// ---------------------------------------------------------------------------
|
|
121 |
//
|
|
122 |
HBufC* CFilesSearcher::GetFilePathArrayIndexValue(TInt aIndex)
|
|
123 |
{
|
|
124 |
return iCompleteFilePathArray[aIndex] ;
|
|
125 |
}
|
|
126 |
|
|
127 |
// ---------------------------------------------------------------------------------
|
|
128 |
// CFilesSearcher::Destroy()
|
|
129 |
// should be called before deleting this object
|
|
130 |
// ---------------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
void CFilesSearcher::Destroy()
|
|
133 |
{
|
|
134 |
if ( IsActive() )
|
|
135 |
{
|
|
136 |
CActive::Cancel();
|
|
137 |
}
|
|
138 |
else
|
|
139 |
{
|
|
140 |
CleanUp();
|
|
141 |
}
|
|
142 |
|
|
143 |
iFs.Close();
|
|
144 |
delete this;
|
|
145 |
|
|
146 |
}
|
|
147 |
|
|
148 |
// ---------------------------------------------------------------------------------
|
|
149 |
// CFilesSearcher::SearchL
|
|
150 |
// Starts the search
|
|
151 |
// ---------------------------------------------------------------------------------
|
|
152 |
//
|
|
153 |
void CFilesSearcher::SearchL()
|
|
154 |
{
|
|
155 |
|
|
156 |
if(0 < iHeavyResultsArray.Count())
|
|
157 |
{
|
|
158 |
iHeavyResultsArray.ResetAndDestroy();
|
|
159 |
//iLightResultsArray.Reset();
|
|
160 |
|
|
161 |
}
|
|
162 |
if( 0 < iCompleteFilePathArray.Count() )
|
|
163 |
iCompleteFilePathArray.ResetAndDestroy();
|
|
164 |
|
|
165 |
/*else
|
|
166 |
{
|
|
167 |
iLightResultsArray.ResetAndDestroy();
|
|
168 |
}*/
|
|
169 |
|
|
170 |
iHeavyResultsAsked = EFalse;
|
|
171 |
iFolder = HBufC::NewL(KMaxFileName);
|
|
172 |
iFileName = HBufC::NewL(KMaxFileName);
|
|
173 |
//iResults.ResetAndDestroy(); ???
|
|
174 |
|
|
175 |
TRequestStatus* status = &iStatus;
|
|
176 |
User::RequestComplete( status, KErrNone );
|
|
177 |
SetActive();
|
|
178 |
}
|
|
179 |
|
|
180 |
// ---------------------------------------------------------------------------------
|
|
181 |
// CFilesSearcher::IsSearching()
|
|
182 |
// Returns TRUE if search is in progress
|
|
183 |
// ---------------------------------------------------------------------------------
|
|
184 |
//
|
|
185 |
TBool CFilesSearcher::IsSearching()
|
|
186 |
{
|
|
187 |
return IsActive();
|
|
188 |
}
|
|
189 |
|
|
190 |
// ---------------------------------------------------------------------------------
|
|
191 |
// CFilesSearcher::CancelSearch()
|
|
192 |
// Cancels the search
|
|
193 |
// ---------------------------------------------------------------------------------
|
|
194 |
//
|
|
195 |
void CFilesSearcher::CancelSearch()
|
|
196 |
{
|
|
197 |
CActive::Cancel();
|
|
198 |
}
|
|
199 |
|
|
200 |
// ---------------------------------------------------------------------------------
|
|
201 |
// CFilesSearcher::GetResultsL
|
|
202 |
// Gets the results
|
|
203 |
// ---------------------------------------------------------------------------------
|
|
204 |
//
|
|
205 |
void CFilesSearcher::GetResultsL(
|
|
206 |
const RPointerArray<CSearchDocumentId>& aDocumentIdArray )
|
|
207 |
{
|
|
208 |
|
|
209 |
TInt myArrayIndex;
|
|
210 |
TInt err;
|
|
211 |
RPointerArray<CSearchResult> searchResultArray;
|
|
212 |
for(TInt i = 0 ; i < aDocumentIdArray.Count() ; i++ )
|
|
213 |
{
|
|
214 |
|
|
215 |
|
|
216 |
TInt myArrayIndex = aDocumentIdArray[i]->DocumentId();
|
|
217 |
|
|
218 |
|
|
219 |
if (( aDocumentIdArray[i]->PluginId() == iPluginId ) &&
|
|
220 |
(KSearchCClassFilenamesUid.iUid == aDocumentIdArray[i]->RepositoryId()) )
|
|
221 |
{
|
|
222 |
if(myArrayIndex < iHeavyResultsArray.Count())
|
|
223 |
{
|
|
224 |
CSearchResult* tempHeavy = iHeavyResultsArray[myArrayIndex];
|
|
225 |
if( (&tempHeavy->Title()) && (&tempHeavy->Snippet()))
|
|
226 |
{
|
|
227 |
searchResultArray.Append( iHeavyResultsArray[myArrayIndex]);
|
|
228 |
continue;
|
|
229 |
}
|
|
230 |
|
|
231 |
HBufC* path16 = iCompleteFilePathArray[myArrayIndex];
|
|
232 |
|
|
233 |
TChar backSlash( '\\' );
|
|
234 |
//From the path extract the filename
|
|
235 |
TInt pos1 = path16->LocateReverse( backSlash );
|
|
236 |
TInt len1 = path16->Length();
|
|
237 |
TInt diff = len1 - pos1 - 1; //bypass the backSlash
|
|
238 |
TPtrC ptr( path16->Right( diff ) );
|
|
239 |
HBufC* hDoc = ptr.AllocL();
|
|
240 |
tempHeavy->SetTitleL( *hDoc );
|
|
241 |
|
|
242 |
TPtr docIdPtr = path16->Des();
|
|
243 |
TEntry entry;
|
|
244 |
iFs.Entry( docIdPtr, entry );
|
|
245 |
TBuf<20> len;
|
|
246 |
//If size is more than 1k size should be represented in KBs.
|
|
247 |
if ( 0 == entry.iSize / constant_MB )
|
|
248 |
{
|
|
249 |
if ( entry.iSize / constant_KB )
|
|
250 |
{
|
|
251 |
|
|
252 |
StringLoader::Format( len, *iSizeKB, -1,
|
|
253 |
entry.iSize / constant_KB );
|
|
254 |
}
|
|
255 |
else
|
|
256 |
{
|
|
257 |
StringLoader::Format( len, *iSizeB, -1,
|
|
258 |
entry.iSize );
|
|
259 |
}
|
|
260 |
}
|
|
261 |
else
|
|
262 |
{
|
|
263 |
StringLoader::Format( len, *iSizeMB, -1,
|
|
264 |
entry.iSize / constant_MB );
|
|
265 |
}
|
|
266 |
TBuf8<20> len8;
|
|
267 |
CnvUtfConverter::ConvertFromUnicodeToUtf8( len8,
|
|
268 |
len );
|
|
269 |
tempHeavy->SetSnippetL( len8 );
|
|
270 |
delete hDoc;
|
|
271 |
hDoc= NULL;
|
|
272 |
|
|
273 |
searchResultArray.Append( tempHeavy );
|
|
274 |
}
|
|
275 |
|
|
276 |
}
|
|
277 |
|
|
278 |
}
|
|
279 |
iObserver->ResultsRetrieveCompleteL( searchResultArray );
|
|
280 |
|
|
281 |
searchResultArray.Reset();
|
|
282 |
|
|
283 |
}
|
|
284 |
|
|
285 |
// ---------------------------------------------------------------------------------
|
|
286 |
// CFilesSearcher::CancelResultsRetrieve()
|
|
287 |
// Cancels the result retrieval
|
|
288 |
// ---------------------------------------------------------------------------------
|
|
289 |
//
|
|
290 |
void CFilesSearcher::CancelResultsRetrieve()
|
|
291 |
{
|
|
292 |
|
|
293 |
}
|
|
294 |
|
|
295 |
// ---------------------------------------------------------------------------------
|
|
296 |
// CFilesSearcher::GetSearchProgressL
|
|
297 |
// Returns the search progress
|
|
298 |
// ---------------------------------------------------------------------------------
|
|
299 |
//
|
|
300 |
void CFilesSearcher::GetSearchProgressL( TUid& /*aContentClassId*/, TInt& /*aCurrentDocument*/, TInt& /*aTotalDocuments*/ )
|
|
301 |
{
|
|
302 |
|
|
303 |
}
|
|
304 |
|
|
305 |
// ---------------------------------------------------------------------------------
|
|
306 |
// CFilesSearcher::HitL()
|
|
307 |
// Called when a result is found matching the search criteria
|
|
308 |
// ---------------------------------------------------------------------------------
|
|
309 |
//
|
|
310 |
void CFilesSearcher::HitL( TInt /*aResult*/ )
|
|
311 |
{
|
|
312 |
CSearchLightResult* searchResult = NULL;
|
|
313 |
CSearchDocumentId* searchDocId = NULL;
|
|
314 |
|
|
315 |
|
|
316 |
//File path is used as the DocumentId to uniquely identify
|
|
317 |
//a file
|
|
318 |
TBuf8<KBufferLength> tempDes;
|
|
319 |
|
|
320 |
|
|
321 |
searchDocId = CSearchDocumentId::NewL( iTotalHits,iPluginId );
|
|
322 |
searchDocId->SetRepositoryIdL( KSearchCClassFilenamesUid.iUid );
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
CleanupStack::PushL( searchDocId );
|
|
327 |
|
|
328 |
|
|
329 |
HBufC* path = HBufC::NewLC( KMaxFileName ) ;
|
|
330 |
path->Des().Append( *iFolder );
|
|
331 |
path->Des().Append( *iFileName );
|
|
332 |
iCompleteFilePathArray.AppendL(path);
|
|
333 |
|
|
334 |
//CnvUtfConverter::ConvertFromUnicodeToUtf8( refBuf, *path );
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
searchResult = CSearchLightResult::NewL( searchDocId );
|
|
339 |
searchResult->SetServiceId( KNullUid );
|
|
340 |
//Set the content class Id as KSearchCClassFilenamesUid
|
|
341 |
searchResult->SetContentClassId( KSearchCClassFilenamesUid );
|
|
342 |
//If file is found from memory card
|
|
343 |
_LIT( KMemCard, "F:" );
|
|
344 |
TInt found = path->Find( KMemCard );
|
|
345 |
if ( !found )
|
|
346 |
{
|
|
347 |
//Set subcontentId as KSearchCSubContentMMCUid
|
|
348 |
searchResult->SetSubContentId( KSearchCSubContentMMCUid.iUid );
|
|
349 |
}
|
|
350 |
|
|
351 |
CSearchResult* searchHeavyResult = CSearchResult::NewL( searchResult);
|
|
352 |
searchHeavyResult->SetSnippetL(KNullDesC8);
|
|
353 |
searchHeavyResult->SetTitleL(KNullDesC);
|
|
354 |
iHeavyResultsArray.Append( searchHeavyResult );
|
|
355 |
|
|
356 |
//iLightResultsArray.AppendL( searchResult );
|
|
357 |
CleanupStack::Pop( path );
|
|
358 |
CleanupStack::Pop( searchDocId );
|
|
359 |
|
|
360 |
iTotalHits++;
|
|
361 |
|
|
362 |
// delete docIdAsString;
|
|
363 |
//docIdAsString = NULL;
|
|
364 |
//Notify the observer about the found result
|
|
365 |
iObserver->ResultFoundL( searchResult, iTotalHits, iCurrentItemCount );
|
|
366 |
}
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
HBufC8* CFilesSearcher::LaunchInfoL( const CSearchDocumentId& aDocumentID )
|
|
372 |
{
|
|
373 |
if((aDocumentID.PluginId() == iPluginId) &&
|
|
374 |
(aDocumentID.RepositoryId() == KSearchCClassFilenamesUid.iUid))
|
|
375 |
{
|
|
376 |
TInt myArrayIndex =aDocumentID.DocumentId() ;
|
|
377 |
TBuf8<KBufferLength> tempDes;
|
|
378 |
HBufC8* launchData = HBufC8::NewL( KBufferLength ) ;
|
|
379 |
CnvUtfConverter::ConvertFromUnicodeToUtf8( tempDes,*iCompleteFilePathArray[myArrayIndex] );
|
|
380 |
launchData->Des().Append(tempDes);
|
|
381 |
return launchData;
|
|
382 |
}
|
|
383 |
return NULL;
|
|
384 |
}
|
|
385 |
|
|
386 |
// ---------------------------------------------------------------------------------
|
|
387 |
// CFilesSearcher::CFilesSearcher()
|
|
388 |
// Constructor
|
|
389 |
// ---------------------------------------------------------------------------------
|
|
390 |
//
|
|
391 |
CFilesSearcher::CFilesSearcher( const TUid& aPluginId ) :
|
|
392 |
CActive( CActive::EPriorityStandard ), iPluginId( aPluginId )
|
|
393 |
,iCurrentDriveIndex( 0 ),iHeavyResultsAsked(EFalse)
|
|
394 |
{
|
|
395 |
CActiveScheduler::Add( this );
|
|
396 |
}
|
|
397 |
|
|
398 |
// ---------------------------------------------------------------------------------
|
|
399 |
// CFilesSearcher::ConstructL()
|
|
400 |
// 2nd phase constructor
|
|
401 |
// ---------------------------------------------------------------------------------
|
|
402 |
//
|
|
403 |
void CFilesSearcher::ConstructL( const RArray<TUid>& /*aContentIdArray*/,
|
|
404 |
const CSearchCondition& aCondition,
|
|
405 |
MSearchPluginObserver& aObserver )
|
|
406 |
{
|
|
407 |
iObserver = &aObserver;
|
|
408 |
//SetPriority( EPriorityStandard );
|
|
409 |
//Create a text searcher
|
|
410 |
if(iFs.Connect() != KErrNone)
|
|
411 |
{
|
|
412 |
return;
|
|
413 |
}
|
|
414 |
iTextSearcher = CSearchTextSearcher::NewL( *this );
|
|
415 |
iTextSearcher->SetParametersL( aCondition );
|
|
416 |
iTotalHits = 0;
|
|
417 |
//Read the process drive letter
|
|
418 |
TPtrC driveLetter = TParsePtrC( RProcess().FileName() ).Drive();
|
|
419 |
TBuf<KMaxFileName> resourceFileName;
|
|
420 |
RResourceFile resourceFile;
|
|
421 |
|
|
422 |
//Read the path of the resource file
|
|
423 |
resourceFileName.Copy( driveLetter );
|
|
424 |
resourceFileName.Append( KDC_RESOURCE_FILES_DIR );
|
|
425 |
_LIT( KResFilename, "avkon.rsc" );
|
|
426 |
resourceFileName.Append( KResFilename );
|
|
427 |
|
|
428 |
//Open the resource file
|
|
429 |
BaflUtils::NearestLanguageFile( iFs, resourceFileName );
|
|
430 |
resourceFile.OpenL( iFs, resourceFileName );
|
|
431 |
resourceFile.ConfirmSignatureL(0);
|
|
432 |
|
|
433 |
//Read "KB" localized string
|
|
434 |
HBufC8* sizeKB = resourceFile.AllocReadLC( R_QTN_SIZE_KB );
|
|
435 |
|
|
436 |
const TPtrC16 ptrReadBuffer( ( TText16* ) sizeKB->Ptr(),
|
|
437 |
( sizeKB->Length()+1 )>>1 );
|
|
438 |
|
|
439 |
TBufC8<KBufferLength> tempString;
|
|
440 |
|
|
441 |
// TPtr8 tempPtr8( tempString.Des() );
|
|
442 |
|
|
443 |
// CnvUtfConverter::ConvertFromUnicodeToUtf8( tempPtr8,
|
|
444 |
// ptrReadBuffer );
|
|
445 |
iSizeKB = ptrReadBuffer.AllocL();
|
|
446 |
|
|
447 |
CleanupStack::PopAndDestroy( sizeKB );
|
|
448 |
//-----------------------------------------------------------------------
|
|
449 |
// tempPtr8.FillZ();
|
|
450 |
|
|
451 |
//Read "B" localized string
|
|
452 |
HBufC8* sizeB = resourceFile.AllocReadLC( R_QTN_SIZE_B );
|
|
453 |
|
|
454 |
const TPtrC16 ptrReadBufferB( ( TText16* ) sizeB->Ptr(),
|
|
455 |
( sizeB->Length()+1 )>>1 );
|
|
456 |
|
|
457 |
|
|
458 |
// CnvUtfConverter::ConvertFromUnicodeToUtf8( tempPtr8,
|
|
459 |
// ptrReadBufferB );
|
|
460 |
iSizeB = ptrReadBufferB.AllocL();
|
|
461 |
|
|
462 |
CleanupStack::PopAndDestroy( sizeB );
|
|
463 |
|
|
464 |
// tempPtr8.FillZ();
|
|
465 |
//-----------------------------------------------------------------------
|
|
466 |
//Read "MB" localized string
|
|
467 |
HBufC8* sizeMB = resourceFile.AllocReadLC( R_QTN_SIZE_MB );
|
|
468 |
|
|
469 |
const TPtrC16 ptrReadBufferMB( ( TText16* ) sizeMB->Ptr(),
|
|
470 |
( sizeMB->Length()+1 )>>1 );
|
|
471 |
|
|
472 |
// CnvUtfConverter::ConvertFromUnicodeToUtf8( tempPtr8,
|
|
473 |
// ptrReadBufferMB );
|
|
474 |
iSizeMB = ptrReadBufferMB.AllocL();
|
|
475 |
|
|
476 |
CleanupStack::PopAndDestroy( sizeMB );
|
|
477 |
|
|
478 |
iFs.DriveList( iDriveList );
|
|
479 |
|
|
480 |
resourceFile.Close();
|
|
481 |
}
|
|
482 |
|
|
483 |
// ---------------------------------------------------------------------------------
|
|
484 |
// CFilesSearcher::ReportFinishedL
|
|
485 |
// Called when search is finished
|
|
486 |
// ---------------------------------------------------------------------------------
|
|
487 |
//
|
|
488 |
void CFilesSearcher::ReportFinishedL()
|
|
489 |
{
|
|
490 |
iObserver->SearchCompletedL( KErrNone, iCurrentItemCount );
|
|
491 |
}
|
|
492 |
|
|
493 |
// ---------------------------------------------------------------------------------
|
|
494 |
// CFilesSearcher::CleanUp()
|
|
495 |
// Cleanup the resources held
|
|
496 |
// ---------------------------------------------------------------------------------
|
|
497 |
//
|
|
498 |
void CFilesSearcher::CleanUp()
|
|
499 |
{
|
|
500 |
|
|
501 |
if ( iFiles )
|
|
502 |
{
|
|
503 |
delete iFiles;
|
|
504 |
iFiles = NULL;
|
|
505 |
}
|
|
506 |
if ( iFolder )
|
|
507 |
{
|
|
508 |
delete iFolder;
|
|
509 |
iFolder = NULL;
|
|
510 |
}
|
|
511 |
|
|
512 |
if ( iFileName )
|
|
513 |
{
|
|
514 |
delete iFileName;
|
|
515 |
iFileName = NULL;
|
|
516 |
}
|
|
517 |
}
|
|
518 |
|
|
519 |
// ---------------------------------------------------------------------------------
|
|
520 |
// CFilesSearcher::IsSystemPath()
|
|
521 |
// If path is system dir/file returns TRUE
|
|
522 |
// ---------------------------------------------------------------------------------
|
|
523 |
//
|
|
524 |
TBool CFilesSearcher::IsSystemPath( TDesC& aPath )
|
|
525 |
{
|
|
526 |
|
|
527 |
return ! (
|
|
528 |
KErrNotFound == aPath.Find( KDC_RESOURCE_FILES_DIR ) &&
|
|
529 |
KErrNotFound == aPath.Find( KSkipPrivate ) &&
|
|
530 |
KErrNotFound == aPath.Find( KSkipSys ) &&
|
|
531 |
KErrNotFound == aPath.Find( KSkipRta ) &&
|
|
532 |
KErrNotFound == aPath.Find( KSkipSystem ) &&
|
|
533 |
KErrNotFound == aPath.Find( KSkipSysTest ) &&
|
|
534 |
KErrNotFound == aPath.Find( KSkipTef ) &&
|
|
535 |
KErrNotFound == aPath.Find( KSkipSmokeTest ) &&
|
|
536 |
KErrNotFound == aPath.Find( KSkipResource ) &&
|
|
537 |
KErrNotFound == aPath.Find( KSkipResourceDir ) &&
|
|
538 |
KErrNotFound == aPath.Find( KSkipNokia ) &&
|
|
539 |
KErrNotFound == aPath.Find( KSkipCDriveTFW ) &&
|
|
540 |
KErrNotFound == aPath.Find( KSkipCDrivePredic ) &&
|
|
541 |
KErrNotFound == aPath.Find( KSkipCNokia ) &&
|
|
542 |
KErrNotFound == aPath.Find( KSkipCDriveLogs ) );
|
|
543 |
|
|
544 |
}
|
|
545 |
|
|
546 |
// ---------------------------------------------------------------------------------
|
|
547 |
// CFilesSearcher::GetFileNameArrayL
|
|
548 |
// Searches through all files in a given folder and it's subfolders recursively.
|
|
549 |
// ---------------------------------------------------------------------------------
|
|
550 |
//
|
|
551 |
void CFilesSearcher::GetFileNameArrayL(
|
|
552 |
const TDesC& aFolder )
|
|
553 |
{
|
|
554 |
if ( iFolder )
|
|
555 |
{
|
|
556 |
delete iFolder;
|
|
557 |
iFolder = NULL;
|
|
558 |
}
|
|
559 |
iFolder = HBufC::NewL( KMaxFileName );
|
|
560 |
iFolder->Des().Append( aFolder );
|
|
561 |
|
|
562 |
iCurrentItemCount++;
|
|
563 |
|
|
564 |
if ( BaflUtils::PathExists( iFs, aFolder ) )
|
|
565 |
{
|
|
566 |
if ( iFiles )
|
|
567 |
{
|
|
568 |
delete iFiles;
|
|
569 |
iFiles = NULL;
|
|
570 |
}
|
|
571 |
CDir* folders = NULL;
|
|
572 |
User::LeaveIfError( iFs.GetDir( aFolder, KEntryAttNormal,
|
|
573 |
ESortByName, iFiles, folders ) );
|
|
574 |
CleanupStack::PushL( folders );
|
|
575 |
|
|
576 |
//Go through all the files in this folder
|
|
577 |
for ( TInt i=0; i < iFiles->Count(); i++ )
|
|
578 |
{
|
|
579 |
iFileName->Des().Zero();
|
|
580 |
iFileName->Des().Append( iFiles->operator[](i).iName );
|
|
581 |
iTextSearcher->Cleanup();
|
|
582 |
TBool fileInCDrive = EFalse;
|
|
583 |
TBool isFolder = EFalse;
|
|
584 |
|
|
585 |
BaflUtils::IsFolder( iFs, *iFileName, isFolder );
|
|
586 |
|
|
587 |
if ( 0 == iFileName->Find( KSkipCDrive ) && !isFolder )
|
|
588 |
{
|
|
589 |
fileInCDrive = ETrue;
|
|
590 |
}
|
|
591 |
if ( !fileInCDrive )
|
|
592 |
{
|
|
593 |
iTextSearcher->SearchL( *iFileName );
|
|
594 |
}
|
|
595 |
|
|
596 |
}
|
|
597 |
|
|
598 |
TInt folderCount = folders->Count();
|
|
599 |
|
|
600 |
//Recursively search in the sub-folders
|
|
601 |
for ( TInt j=0; j < folderCount ; j++ )
|
|
602 |
{
|
|
603 |
iFileName->Des().Zero();
|
|
604 |
iFileName->Des().Append(folders->operator[](j).iName);
|
|
605 |
|
|
606 |
/* //Since its a folder dont search for it..
|
|
607 |
|
|
608 |
iTextSearcher->Cleanup();
|
|
609 |
iTextSearcher->SearchL( *iFileName );
|
|
610 |
*/
|
|
611 |
|
|
612 |
HBufC* tempBuf = HBufC::NewLC( KMaxFileName );
|
|
613 |
TPtr fileName( tempBuf->Des() );
|
|
614 |
fileName.Copy( aFolder );
|
|
615 |
fileName.Append( folders->operator[](j).iName );
|
|
616 |
_LIT ( KBackSlash, "\\" );
|
|
617 |
fileName.Append( KBackSlash );
|
|
618 |
|
|
619 |
/* Do not search system folders under any circumstances. */
|
|
620 |
|
|
621 |
if ( !IsSystemPath( fileName ) )
|
|
622 |
{
|
|
623 |
GetFileNameArrayL( fileName );
|
|
624 |
}
|
|
625 |
CleanupStack::PopAndDestroy( tempBuf );
|
|
626 |
}
|
|
627 |
|
|
628 |
CleanupStack::PopAndDestroy( folders );
|
|
629 |
}
|
|
630 |
|
|
631 |
}
|
|
632 |
|
|
633 |
// ---------------------------------------------------------------------------------
|
|
634 |
// CFileSearcher::DoActualSearchL()
|
|
635 |
// Does the search for the file. Called from RunL. In one RunL call
|
|
636 |
// a limited number of file names are searched.
|
|
637 |
// Return: ETrue: if more note items need to be searched.
|
|
638 |
// EFalse: otherwise.
|
|
639 |
// ---------------------------------------------------------------------------------
|
|
640 |
//
|
|
641 |
TBool CFilesSearcher::DoActualSearchL()
|
|
642 |
{
|
|
643 |
|
|
644 |
// Get list of all files to be searched
|
|
645 |
// Search is divided for better responsiveness
|
|
646 |
|
|
647 |
while( ETrue )
|
|
648 |
{
|
|
649 |
TChar driveLetter1 = iDriveList[iCurrentDriveIndex];
|
|
650 |
//If the Drive is present
|
|
651 |
if ( iDriveList[iCurrentDriveIndex] )
|
|
652 |
{
|
|
653 |
//Check for the BAD DRIVE
|
|
654 |
if ( iCurrentDriveIndex < KMaxDrives )
|
|
655 |
{
|
|
656 |
//Get the drive name
|
|
657 |
TDriveUnit xyz( iCurrentDriveIndex );
|
|
658 |
TDriveName let = xyz.Name();
|
|
659 |
|
|
660 |
//Path variable
|
|
661 |
HBufC* pathList = HBufC::NewLC( KMaxFileName );
|
|
662 |
pathList->Des().Append( let );
|
|
663 |
_LIT ( KBackSlash, "\\" );
|
|
664 |
pathList->Des().Append( KBackSlash );
|
|
665 |
|
|
666 |
//Search recursively all the folders and
|
|
667 |
//subfolders in the drive
|
|
668 |
GetFileNameArrayL( *pathList );
|
|
669 |
CleanupStack::PopAndDestroy(pathList);
|
|
670 |
|
|
671 |
iCurrentDriveIndex++;
|
|
672 |
if ( KMaxDrives <= iCurrentDriveIndex )
|
|
673 |
{
|
|
674 |
return EFalse; //If have searched all the drives
|
|
675 |
}
|
|
676 |
return ETrue;
|
|
677 |
}
|
|
678 |
|
|
679 |
}
|
|
680 |
else
|
|
681 |
{
|
|
682 |
iCurrentDriveIndex++;
|
|
683 |
if ( KMaxDrives <= iCurrentDriveIndex )
|
|
684 |
{
|
|
685 |
return EFalse; //If have searched all the drives
|
|
686 |
}
|
|
687 |
}
|
|
688 |
|
|
689 |
}
|
|
690 |
}
|
|
691 |
|
|
692 |
// ---------------------------------------------------------------------------------
|
|
693 |
// CFilesSearcher::DoCancel()
|
|
694 |
// Called by ECOM framework
|
|
695 |
// ---------------------------------------------------------------------------------
|
|
696 |
//
|
|
697 |
void CFilesSearcher::DoCancel()
|
|
698 |
{
|
|
699 |
CleanUp();
|
|
700 |
}
|
|
701 |
|
|
702 |
|
|
703 |
// ---------------------------------------------------------------------------------
|
|
704 |
// CFilesSearcher::RunL
|
|
705 |
// Called by ECOM framework
|
|
706 |
// ---------------------------------------------------------------------------------
|
|
707 |
//
|
|
708 |
void CFilesSearcher::RunL()
|
|
709 |
{
|
|
710 |
TBool continueSearch = EFalse;
|
|
711 |
|
|
712 |
TRAPD( err, continueSearch = DoActualSearchL() );
|
|
713 |
if ( err != KErrNone )
|
|
714 |
{
|
|
715 |
iObserver->SearchCompletedL( err, iCurrentItemCount );
|
|
716 |
}
|
|
717 |
else
|
|
718 |
{
|
|
719 |
if ( continueSearch )
|
|
720 |
{
|
|
721 |
TRequestStatus* status = &iStatus;
|
|
722 |
User::RequestComplete( status, KErrNone );
|
|
723 |
SetActive();
|
|
724 |
}
|
|
725 |
else
|
|
726 |
{
|
|
727 |
ReportFinishedL();
|
|
728 |
}
|
|
729 |
}
|
|
730 |
|
|
731 |
}
|
|
732 |
|
|
733 |
|
|
734 |
// ---------------------------------------------------------------------------------
|
|
735 |
// CFilesSearcher::RunError
|
|
736 |
// Called by ECOM framework
|
|
737 |
// ---------------------------------------------------------------------------------
|
|
738 |
//
|
|
739 |
TInt CFilesSearcher::RunError()
|
|
740 |
{
|
|
741 |
return KErrNone;
|
|
742 |
}
|
|
743 |
|