0
|
1 |
/*
|
|
2 |
* Copyright (c) 2004 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 |
#include "FolderScanner.h"
|
|
21 |
|
|
22 |
EXPORT_C CFolderScanner::~CFolderScanner()
|
|
23 |
{
|
|
24 |
iFs.Close();
|
|
25 |
delete iTimer;
|
|
26 |
delete iFolder;
|
|
27 |
delete iScanExt;
|
|
28 |
}
|
|
29 |
|
|
30 |
void CFolderScanner::ConstructL( CFolderScanner_if* client
|
|
31 |
, const TDesC& folder
|
|
32 |
, const TDesC& ext
|
|
33 |
, int aScanPeriod)
|
|
34 |
|
|
35 |
{
|
|
36 |
iClient = client;
|
|
37 |
iTimeout = aScanPeriod;
|
|
38 |
|
|
39 |
iFolder = folder.AllocL();
|
|
40 |
iScanExt = ext.AllocL();
|
|
41 |
|
|
42 |
User::LeaveIfError(iFs.Connect());
|
|
43 |
|
|
44 |
// Check that folder really exist
|
|
45 |
TEntry entry;
|
|
46 |
TInt err = iFs.Entry(folder, entry);
|
|
47 |
|
|
48 |
// If not found, attempt to create
|
|
49 |
if(err == KErrNotFound)
|
|
50 |
{
|
|
51 |
err = iFs.MkDirAll(*iFolder);
|
|
52 |
}
|
|
53 |
User::LeaveIfError(err);
|
|
54 |
|
|
55 |
// Create a timer
|
|
56 |
iTimer = CSysTimer::NewL(this, 0);
|
|
57 |
|
|
58 |
// we want first callback immediately
|
|
59 |
iTimer->MilliSeconds(0);
|
|
60 |
}
|
|
61 |
|
|
62 |
EXPORT_C CFolderScanner* CFolderScanner::NewL( CFolderScanner_if* client
|
|
63 |
, const TDesC& folder
|
|
64 |
, const TDesC& ext
|
|
65 |
, int aScanPeriod)
|
|
66 |
{
|
|
67 |
CFolderScanner* self = new (ELeave)CFolderScanner();
|
|
68 |
CleanupStack::PushL(self);
|
|
69 |
self->ConstructL(client, folder, ext, aScanPeriod);
|
|
70 |
CleanupStack::Pop();
|
|
71 |
return self;
|
|
72 |
}
|
|
73 |
|
|
74 |
void CFolderScanner::Timer(int)
|
|
75 |
{
|
|
76 |
if(ScanOnce() == false)
|
|
77 |
{
|
|
78 |
iTimer->MilliSeconds(iTimeout);
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
|
82 |
/*
|
|
83 |
* Scan folders contents once
|
|
84 |
*/
|
|
85 |
inline bool CFolderScanner::ScanOnce()
|
|
86 |
{
|
|
87 |
// Perform scan
|
|
88 |
CDir* SMSInList = NULL;
|
|
89 |
if (iFs.GetDir(*iFolder,KEntryAttNormal,ESortNone,SMSInList) == KErrNone)
|
|
90 |
{
|
|
91 |
for(TInt i = 0; i<SMSInList->Count(); i++)
|
|
92 |
{
|
|
93 |
// if we're given a wild card, we ignore chars before '.'
|
|
94 |
// just extension chars?
|
|
95 |
const TEntry& entry = (*SMSInList)[i];
|
|
96 |
if (!entry.IsDir())
|
|
97 |
{
|
|
98 |
TPtrC ext(entry.iName.Mid(entry.iName.LocateReverse('.')));
|
|
99 |
if (!ext.CompareF(iScanExt->Mid(iScanExt->LocateReverse('.'))))
|
|
100 |
{
|
|
101 |
TFileName fileName;
|
|
102 |
fileName.Append(*iFolder);
|
|
103 |
fileName.Append(entry.iName);
|
|
104 |
iClient->FileFound(fileName);
|
|
105 |
delete SMSInList;
|
|
106 |
return true;
|
|
107 |
}
|
|
108 |
}
|
|
109 |
}
|
|
110 |
delete SMSInList;
|
|
111 |
}
|
|
112 |
return false;
|
|
113 |
}
|
|
114 |
|
|
115 |
/*
|
|
116 |
* We continue scanning by getting a callback asap
|
|
117 |
*/
|
|
118 |
EXPORT_C void CFolderScanner::ContinueScan()
|
|
119 |
{
|
|
120 |
iTimer->MilliSeconds(0);
|
|
121 |
}
|