1 /* |
|
2 * Copyright (c) 2002-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: Goes through folder tree one item at time |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CFileManagerFileSystemIterator.h" |
|
22 #include "CFileManagerEngine.h" |
|
23 #include "CFileManagerCommonDefinitions.h" |
|
24 |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CFileManagerFileSystemIterator::NewL |
|
30 // |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CFileManagerFileSystemIterator* CFileManagerFileSystemIterator::NewL( |
|
34 RFs& aFs, |
|
35 const TDesC& aSrcDir, |
|
36 const TDesC& aDstDir, |
|
37 CFileManagerEngine& aEngine ) |
|
38 { |
|
39 CFileManagerFileSystemIterator* self = |
|
40 new (ELeave) CFileManagerFileSystemIterator( aDstDir, aEngine ); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL( aFs, aSrcDir ); |
|
43 CleanupStack::Pop( self ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CFileManagerFileSystemIterator::CFileManagerFileSystemIterator |
|
49 // |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CFileManagerFileSystemIterator::CFileManagerFileSystemIterator( |
|
53 const TDesC& aDstDir, CFileManagerEngine& aEngine ) : |
|
54 iCount( KErrNotFound ), |
|
55 iDstDir( aDstDir ), |
|
56 iEngine( aEngine ) |
|
57 { |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CFileManagerFileSystemIterator::~CFileManagerFileSystemIterator |
|
62 // |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CFileManagerFileSystemIterator::~CFileManagerFileSystemIterator() |
|
66 { |
|
67 delete iSrcDir; |
|
68 delete iSrc; |
|
69 delete iDst; |
|
70 delete iDir; |
|
71 delete iDirScan; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CFileManagerFileSystemIterator::ConstructL |
|
76 // |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void CFileManagerFileSystemIterator::ConstructL( |
|
80 RFs& aFs, const TDesC& aSrcDir ) |
|
81 { |
|
82 iDirScan = CDirScan::NewL( aFs ); |
|
83 // Go through the folders first |
|
84 iDirScan->SetScanDataL( |
|
85 aSrcDir, |
|
86 KEntryAttNormal | KEntryAttHidden | KEntryAttSystem | |
|
87 KEntryAttDir | KEntryAttMatchExclusive, |
|
88 ESortNone ); |
|
89 iSrc = HBufC::NewL( KMaxFileName ); |
|
90 // We need double destination size |
|
91 // because source and target folder can be |
|
92 // KMaxFileName sized and those are append |
|
93 // to same buffer. |
|
94 iDst = HBufC::NewL( KFmgrDoubleMaxFileName ); |
|
95 iDst->Des().Copy( iDstDir ); |
|
96 iDirScan->NextL( iDir ); |
|
97 iSrcDir = aSrcDir.AllocL(); |
|
98 iSrc->Des().Copy( aSrcDir ); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CFileManagerFileSystemIterator::CurrentL |
|
103 // |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CFileManagerFileSystemIterator::CurrentL( |
|
107 HBufC** aSrc, HBufC** aDst, TFileManagerTypeOfItem& aItemType ) |
|
108 { |
|
109 *aSrc = NULL; |
|
110 *aDst = NULL; |
|
111 |
|
112 if( iCount == KErrNotFound ) |
|
113 { |
|
114 // Handle destination root folder first |
|
115 aItemType = EFileManagerFolder; |
|
116 *aSrc = iSrc; // contains iSrcDir |
|
117 *aDst = iDst; // contains iDstDir |
|
118 } |
|
119 else if( iDir && iCount < iDir->Count() ) |
|
120 { |
|
121 // Handle folder contents |
|
122 if( !iFolderScanDone ) |
|
123 { |
|
124 const TEntry& entry( ( *iDir )[ iCount ] ); |
|
125 |
|
126 TPtr ptrSrc( iSrc->Des() ); |
|
127 ptrSrc.Copy( iDirScan->FullPath() ); |
|
128 ptrSrc.Append( entry.iName ); |
|
129 ptrSrc.Append( KFmgrBackslash ); |
|
130 |
|
131 TPtr ptrDst( iDst->Des() ); |
|
132 ptrDst.Copy( iDstDir ); |
|
133 ptrDst.Append( LocalizedAbbreviatedPath() ); |
|
134 |
|
135 TPtrC ptr( iEngine.LocalizedName( *iSrc ) ); |
|
136 if( ptr.Length() ) |
|
137 { |
|
138 ptrDst.Append( ptr ); |
|
139 } |
|
140 else |
|
141 { |
|
142 ptrDst.Append( entry.iName ); |
|
143 } |
|
144 ptrDst.Append( KFmgrBackslash ); |
|
145 |
|
146 aItemType = EFileManagerFolder; |
|
147 } |
|
148 else |
|
149 { |
|
150 const TEntry& entry( ( *iDir )[ iCount ] ); |
|
151 |
|
152 TPtr ptrSrc( iSrc->Des() ); |
|
153 ptrSrc.Copy( iDirScan->FullPath() ); |
|
154 ptrSrc.Append( entry.iName ); |
|
155 |
|
156 TPtr ptrDst( iDst->Des() ); |
|
157 ptrDst.Copy( iDstDir ); |
|
158 ptrDst.Append( LocalizedAbbreviatedPath() ); |
|
159 ptrDst.Append( entry.iName ); |
|
160 |
|
161 aItemType = EFileManagerFile; |
|
162 } |
|
163 *aSrc = iSrc; |
|
164 *aDst = iDst; |
|
165 } |
|
166 else |
|
167 { |
|
168 aItemType = EFileManagerNoType; |
|
169 } |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CFileManagerFileSystemIterator::NextL |
|
174 // |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TBool CFileManagerFileSystemIterator::NextL() |
|
178 { |
|
179 if ( !iDir ) |
|
180 { |
|
181 return EFalse; |
|
182 } |
|
183 |
|
184 ++iCount; |
|
185 |
|
186 // Get next dir |
|
187 if( iCount >= iDir->Count() ) |
|
188 { |
|
189 delete iDir; |
|
190 iDir = NULL; |
|
191 iCount = 0; |
|
192 iDirScan->NextL( iDir ); |
|
193 iLocalizedAbbreviatedPath.Zero(); |
|
194 } |
|
195 |
|
196 // Are we done |
|
197 if( iDir ) |
|
198 { |
|
199 return ETrue; |
|
200 } |
|
201 |
|
202 // Folders have been scanned through, now same scanning with files |
|
203 if( !iFolderScanDone ) |
|
204 { |
|
205 iDirScan->SetScanDataL( *iSrcDir, |
|
206 KEntryAttNormal | KEntryAttHidden | KEntryAttSystem, |
|
207 ESortNone ); |
|
208 iDirScan->NextL( iDir ); |
|
209 iLocalizedAbbreviatedPath.Zero(); |
|
210 iCount = 0; |
|
211 iFolderScanDone = ETrue; |
|
212 return ETrue; |
|
213 } |
|
214 |
|
215 return EFalse; |
|
216 } |
|
217 |
|
218 // ------------------------------------------------------------------------------ |
|
219 // CFileManagerFileSystemIterator::LocalizedAbbreviatedPath |
|
220 // |
|
221 // ------------------------------------------------------------------------------ |
|
222 // |
|
223 TPtrC CFileManagerFileSystemIterator::LocalizedAbbreviatedPath() |
|
224 { |
|
225 TPtrC abbrPath( iDirScan->AbbreviatedPath() ); |
|
226 |
|
227 if( !iLocalizedAbbreviatedPath.Length() && abbrPath.Length() > 1 ) |
|
228 { |
|
229 iLocalizedAbbreviatedPath.Append( |
|
230 iEngine.LocalizedName( iDirScan->FullPath() ) ); |
|
231 |
|
232 if( !iLocalizedAbbreviatedPath.Length() ) |
|
233 { |
|
234 iLocalizedAbbreviatedPath.Append( |
|
235 abbrPath.Right( abbrPath.Length() - 1 ) ); |
|
236 } |
|
237 else |
|
238 { |
|
239 iLocalizedAbbreviatedPath.Append( KFmgrBackslash ); |
|
240 } |
|
241 } |
|
242 return iLocalizedAbbreviatedPath; |
|
243 } |
|
244 |
|
245 // End of File |
|