sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <f32file.h>
|
sl@0
|
21 |
#include <apmstd.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "contentIterator.h"
|
sl@0
|
24 |
#include "virtualpath.h"
|
sl@0
|
25 |
#include "content.h"
|
sl@0
|
26 |
#include "manager.h"
|
sl@0
|
27 |
#include "EmbeddedObject.h"
|
sl@0
|
28 |
#include "FileContentIteratorBase.h"
|
sl@0
|
29 |
#include "EmbeddedcontentIterator.h"
|
sl@0
|
30 |
|
sl@0
|
31 |
using namespace ContentAccess;
|
sl@0
|
32 |
|
sl@0
|
33 |
_LIT(KCAFBackSlashCharacter, "\\");
|
sl@0
|
34 |
|
sl@0
|
35 |
|
sl@0
|
36 |
CFileContentIteratorBase* CFileContentIteratorBase::NewL(CManager &aManager, const TDesC& aPath, TBool aRecursive, const TDesC8& aMimeType)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
CFileContentIteratorBase* self = new (ELeave) CFileContentIteratorBase(aManager, aPath, aRecursive, aMimeType);
|
sl@0
|
39 |
CleanupStack::PushL(self);
|
sl@0
|
40 |
self->ConstructL();
|
sl@0
|
41 |
CleanupStack::Pop(self);
|
sl@0
|
42 |
return self;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
CFileContentIteratorBase::CFileContentIteratorBase(CManager& aManager, const TDesC& aPath, TBool aRecursive, const TDesC8& aMimeType) :
|
sl@0
|
46 |
iManager(aManager), iPath(aPath), iRecursive(aRecursive), iMimeType(aMimeType)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
iDirIndex = 0;
|
sl@0
|
49 |
iFileIndex = 0;
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
void CFileContentIteratorBase::ConstructL()
|
sl@0
|
53 |
{
|
sl@0
|
54 |
// Get our list of files and directories
|
sl@0
|
55 |
User::LeaveIfError(iManager.GetDir(iPath, ESortByName, KEntryAttNormal, iCurrentFileList, iCurrentDirectoryList));
|
sl@0
|
56 |
|
sl@0
|
57 |
if(!iRecursive)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
// Won't be needing the list of directories
|
sl@0
|
60 |
delete iCurrentDirectoryList;
|
sl@0
|
61 |
iCurrentDirectoryList = NULL;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
// Find the Next, (ie. first content object) inside this directory
|
sl@0
|
65 |
// This will leave if nothing was found
|
sl@0
|
66 |
User::LeaveIfError(Next());
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
CFileContentIteratorBase::~CFileContentIteratorBase()
|
sl@0
|
70 |
{
|
sl@0
|
71 |
delete iSubIterator;
|
sl@0
|
72 |
delete iCurrentDirectoryList;
|
sl@0
|
73 |
delete iCurrentFileList;
|
sl@0
|
74 |
delete iNewPath;
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
const TDesC& CFileContentIteratorBase::FileName() const
|
sl@0
|
78 |
{
|
sl@0
|
79 |
return iSubIterator->FileName();
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
const TDesC& CFileContentIteratorBase::UniqueId() const
|
sl@0
|
83 |
{
|
sl@0
|
84 |
return iSubIterator->UniqueId();
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
const TDesC& CFileContentIteratorBase::Name() const
|
sl@0
|
88 |
{
|
sl@0
|
89 |
return iSubIterator->Name();
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
const TDesC8& CFileContentIteratorBase::MimeType() const
|
sl@0
|
93 |
{
|
sl@0
|
94 |
return iSubIterator->MimeType();
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
TInt CFileContentIteratorBase::Next()
|
sl@0
|
98 |
{
|
sl@0
|
99 |
_LIT(KSysDirEntry, "sys");
|
sl@0
|
100 |
|
sl@0
|
101 |
TInt ret = KErrNotFound;
|
sl@0
|
102 |
|
sl@0
|
103 |
// If we are already looking into some sub container, try finding the next in there
|
sl@0
|
104 |
if(iSubIterator)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
ret = iSubIterator->Next();
|
sl@0
|
107 |
if(ret == KErrNone)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
return ret;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
else
|
sl@0
|
112 |
{
|
sl@0
|
113 |
// Delete sub-iterator
|
sl@0
|
114 |
delete iSubIterator;
|
sl@0
|
115 |
iSubIterator = NULL;
|
sl@0
|
116 |
delete iNewPath;
|
sl@0
|
117 |
iNewPath = NULL;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
|
sl@0
|
122 |
// Search files in our directory first
|
sl@0
|
123 |
// this allows us to free memory used by iCurrentFileList
|
sl@0
|
124 |
// before recursing into sub-directories
|
sl@0
|
125 |
if(iCurrentFileList)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
for ( ; iFileIndex < iCurrentFileList->Count(); iFileIndex++)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
// Get a reference to the file we are interested in
|
sl@0
|
130 |
const TEntry &entry = (*iCurrentFileList)[iFileIndex];
|
sl@0
|
131 |
|
sl@0
|
132 |
// create a new path string for the sub directory
|
sl@0
|
133 |
TRAP(ret, iNewPath = HBufC::NewL(iPath.Length() + entry.iName.Length()));
|
sl@0
|
134 |
if(ret != KErrNone)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
return ret;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
iNewPath->Des().Append(iPath);
|
sl@0
|
139 |
iNewPath->Des().Append(entry.iName);
|
sl@0
|
140 |
|
sl@0
|
141 |
// Look inside the file
|
sl@0
|
142 |
TRAP(ret, iSubIterator = CEmbeddedContentIterator::NewL(TVirtualPathPtr(*iNewPath, KNullDesC()), iRecursive, iMimeType));
|
sl@0
|
143 |
|
sl@0
|
144 |
if(ret == KErrNone)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
// must have found something in the file
|
sl@0
|
147 |
// make sure next time we look at the next item in our list
|
sl@0
|
148 |
iFileIndex++;
|
sl@0
|
149 |
return KErrNone;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
// next iteration
|
sl@0
|
152 |
delete iNewPath;
|
sl@0
|
153 |
iNewPath = NULL;
|
sl@0
|
154 |
}
|
sl@0
|
155 |
delete iCurrentFileList;
|
sl@0
|
156 |
iCurrentFileList = NULL;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
|
sl@0
|
160 |
if(iRecursive)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
// Search sub directories
|
sl@0
|
163 |
for ( ; iDirIndex < iCurrentDirectoryList->Count(); iDirIndex++)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
// Get a reference to the directory we are interested in
|
sl@0
|
166 |
const TEntry &entry = (*iCurrentDirectoryList)[iDirIndex];
|
sl@0
|
167 |
|
sl@0
|
168 |
// make sure it's not the sys directory
|
sl@0
|
169 |
if(KSysDirEntry().CompareF(entry.iName) == 0 && iPath.Length() == 3)
|
sl@0
|
170 |
{
|
sl@0
|
171 |
// go to the next iteration, skip the sys directory
|
sl@0
|
172 |
continue;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
// create a new path string for the sub directory
|
sl@0
|
176 |
TRAP(ret, iNewPath = HBufC::NewL(iPath.Length() + 1 + entry.iName.Length()));
|
sl@0
|
177 |
if(ret != KErrNone)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
return ret;
|
sl@0
|
180 |
}
|
sl@0
|
181 |
iNewPath->Des().Append(iPath);
|
sl@0
|
182 |
iNewPath->Des().Append(entry.iName);
|
sl@0
|
183 |
iNewPath->Des().Append(KCAFBackSlashCharacter);
|
sl@0
|
184 |
|
sl@0
|
185 |
|
sl@0
|
186 |
// lets look inside the directory
|
sl@0
|
187 |
TRAP(ret, iSubIterator = CFileContentIteratorBase::NewL(iManager, *iNewPath, iRecursive, iMimeType));
|
sl@0
|
188 |
|
sl@0
|
189 |
if(ret == KErrNone)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
// must have found something in the sub-iterator
|
sl@0
|
192 |
// make sure next time we look at the next item in our list
|
sl@0
|
193 |
iDirIndex++;
|
sl@0
|
194 |
return KErrNone;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
// next iteration
|
sl@0
|
197 |
delete iNewPath;
|
sl@0
|
198 |
iNewPath = NULL;
|
sl@0
|
199 |
}
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
// reached the end of our list of directories and list of files
|
sl@0
|
203 |
return KErrNotFound;
|
sl@0
|
204 |
}
|