0
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2009 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 the License "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 |
@test
|
|
20 |
@internalComponent
|
|
21 |
v
|
|
22 |
This contains CT_DirData
|
|
23 |
*/
|
|
24 |
|
|
25 |
// User includes
|
|
26 |
#include "T_DirData.h"
|
|
27 |
#include "T_SfSrvServer.h"
|
|
28 |
|
|
29 |
/*@{*/
|
|
30 |
/// Parameters
|
|
31 |
_LIT(KArrayElementNumber, "element_number");
|
|
32 |
_LIT(KExpected, "expected");
|
|
33 |
_LIT(KSortkey, "sortkey");
|
|
34 |
_LIT(KNumSortkey, "numsortkey");
|
|
35 |
_LIT(KEntryObject, "entryObject");
|
|
36 |
|
|
37 |
///Commands
|
|
38 |
_LIT(KCmdCount, "Count");
|
|
39 |
_LIT(KCmdOperatorBrackets, "[]");
|
|
40 |
_LIT(KCmdSort, "Sort");
|
|
41 |
_LIT(KCmdDestructor, "~");
|
|
42 |
|
|
43 |
|
|
44 |
//Sort keys
|
|
45 |
_LIT(KESortNone, "ESortNone");
|
|
46 |
_LIT(KESortByName, "ESortByName");
|
|
47 |
_LIT(KESortByExt, "ESortByExt");
|
|
48 |
_LIT(KESortBySize, "ESortBySize");
|
|
49 |
_LIT(KESortByDate, "ESortByDate");
|
|
50 |
_LIT(KESortByUid, "ESortByUid");
|
|
51 |
_LIT(KEDirsAnyOrder, "EDirsAnyOrder");
|
|
52 |
_LIT(KEDirsFirst, "EDirsFirst");
|
|
53 |
_LIT(KEDirsLast, "EDirsLast");
|
|
54 |
_LIT(KEAscending, "EAscending");
|
|
55 |
_LIT(KEDescending, "EDescending");
|
|
56 |
_LIT(KEDirDescending, "EDirDescending");
|
|
57 |
|
|
58 |
|
|
59 |
CT_DirData* CT_DirData::NewL()
|
|
60 |
/**
|
|
61 |
* Two phase constructor
|
|
62 |
*/
|
|
63 |
{
|
|
64 |
CT_DirData* ret = new (ELeave) CT_DirData();
|
|
65 |
CleanupStack::PushL(ret);
|
|
66 |
ret->ConstructL();
|
|
67 |
CleanupStack::Pop(ret);
|
|
68 |
return ret;
|
|
69 |
}
|
|
70 |
|
|
71 |
|
|
72 |
CT_DirData::CT_DirData()
|
|
73 |
: iDir(NULL)
|
|
74 |
/**
|
|
75 |
* Protected constructor. First phase construction
|
|
76 |
*/
|
|
77 |
{
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
void CT_DirData::ConstructL()
|
|
82 |
/**
|
|
83 |
* Protected constructor. Second phase construction
|
|
84 |
*/
|
|
85 |
{
|
|
86 |
}
|
|
87 |
|
|
88 |
|
|
89 |
CT_DirData::~CT_DirData()
|
|
90 |
/**
|
|
91 |
* Destructor.
|
|
92 |
*/
|
|
93 |
{
|
|
94 |
DoCleanup();
|
|
95 |
}
|
|
96 |
|
|
97 |
|
|
98 |
TAny* CT_DirData::GetObject()
|
|
99 |
{
|
|
100 |
return iDir;
|
|
101 |
}
|
|
102 |
|
|
103 |
|
|
104 |
void CT_DirData::SetObjectL(TAny* aAny)
|
|
105 |
{
|
|
106 |
DoCleanup();
|
|
107 |
iDir = static_cast<CDir*> (aAny);
|
|
108 |
}
|
|
109 |
|
|
110 |
|
|
111 |
void CT_DirData::DisownObjectL()
|
|
112 |
{
|
|
113 |
iDir = NULL;
|
|
114 |
}
|
|
115 |
|
|
116 |
|
|
117 |
inline TCleanupOperation CT_DirData::CleanupOperation()
|
|
118 |
{
|
|
119 |
return CleanupOperation;
|
|
120 |
}
|
|
121 |
|
|
122 |
|
|
123 |
void CT_DirData::CleanupOperation(TAny* aAny)
|
|
124 |
{
|
|
125 |
CDir* dir=static_cast<CDir*>(aAny);
|
|
126 |
delete dir;
|
|
127 |
}
|
|
128 |
|
|
129 |
|
|
130 |
TBool CT_DirData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
|
|
131 |
/**
|
|
132 |
* Process a command read from the ini file
|
|
133 |
*
|
|
134 |
* @param aCommand the command to process
|
|
135 |
* @param aSection the entry in the ini file requiring the command to be processed
|
|
136 |
*
|
|
137 |
* @return ETrue if the command is processed
|
|
138 |
*/
|
|
139 |
{
|
|
140 |
TBool retVal = ETrue;
|
|
141 |
|
|
142 |
if (aCommand == KCmdCount)
|
|
143 |
{
|
|
144 |
DoCmdCount(aSection);
|
|
145 |
}
|
|
146 |
else if (aCommand == KCmdOperatorBrackets)
|
|
147 |
{
|
|
148 |
DoCmdOperatorBracketsL(aSection);
|
|
149 |
}
|
|
150 |
else if (aCommand == KCmdSort)
|
|
151 |
{
|
|
152 |
DoCmdSort(aSection);
|
|
153 |
}
|
|
154 |
else if (aCommand == KCmdDestructor)
|
|
155 |
{
|
|
156 |
DoCleanup();
|
|
157 |
}
|
|
158 |
else
|
|
159 |
{
|
|
160 |
retVal = EFalse;
|
|
161 |
}
|
|
162 |
return retVal;
|
|
163 |
}
|
|
164 |
|
|
165 |
|
|
166 |
void CT_DirData::DoCleanup()
|
|
167 |
{
|
|
168 |
INFO_PRINTF1(_L("Doing cleanup"));
|
|
169 |
if (iDir)
|
|
170 |
{
|
|
171 |
delete iDir;
|
|
172 |
iDir = NULL;
|
|
173 |
}
|
|
174 |
}
|
|
175 |
|
|
176 |
void CT_DirData::DoCmdCount(const TDesC& aSection)
|
|
177 |
{
|
|
178 |
INFO_PRINTF1(_L("Counts directory entries!"));
|
|
179 |
|
|
180 |
TInt expected;
|
|
181 |
if (GET_MANDATORY_INT_PARAMETER(KExpected, aSection, expected))
|
|
182 |
{
|
|
183 |
TInt count = iDir->Count();
|
|
184 |
if (count != expected)
|
|
185 |
{
|
|
186 |
ERR_PRINTF3(_L("Result didn't match with expected result! COUNT: %d, expected: %d"), count, expected);
|
|
187 |
SetBlockResult(EFail);
|
|
188 |
}
|
|
189 |
else
|
|
190 |
{
|
|
191 |
INFO_PRINTF2(_L("Result matched with expected result (%d)!"), count);
|
|
192 |
}
|
|
193 |
}
|
|
194 |
}
|
|
195 |
|
|
196 |
|
|
197 |
void CT_DirData::DoCmdOperatorBracketsL(const TDesC& aSection)
|
|
198 |
{
|
|
199 |
INFO_PRINTF1(_L("Getting element and compare it with expected!"));
|
|
200 |
|
|
201 |
TInt elementNumber;
|
|
202 |
|
|
203 |
if (GET_MANDATORY_INT_PARAMETER(KArrayElementNumber, aSection, elementNumber))
|
|
204 |
{
|
|
205 |
INFO_PRINTF2( _L( "Get element[%d]" ), elementNumber);
|
|
206 |
TEntry* entryObject = new(ELeave) TEntry();
|
|
207 |
CleanupStack::PushL(entryObject);
|
|
208 |
|
|
209 |
*entryObject = iDir->operator[](elementNumber);
|
|
210 |
|
|
211 |
if ( !FileserverUtil::VerifyTEntryDataFromIniL(*this, aSection, *entryObject))
|
|
212 |
{
|
|
213 |
SetBlockResult(EFail);
|
|
214 |
}
|
|
215 |
|
|
216 |
TPtrC entryObjectName;
|
|
217 |
if (GET_OPTIONAL_STRING_PARAMETER(KEntryObject, aSection, entryObjectName))
|
|
218 |
{
|
|
219 |
CT_EntryData* entryWrapperObject = static_cast<CT_EntryData*>(GetDataWrapperL(entryObjectName));
|
|
220 |
if(entryWrapperObject)
|
|
221 |
{
|
|
222 |
entryWrapperObject->SetObjectL(entryObject);
|
|
223 |
entryObject = NULL;
|
|
224 |
}
|
|
225 |
else
|
|
226 |
{
|
|
227 |
SetBlockResult(EFail);
|
|
228 |
}
|
|
229 |
}
|
|
230 |
|
|
231 |
CleanupStack::Pop();
|
|
232 |
delete entryObject;
|
|
233 |
entryObject = NULL;
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|
|
237 |
void CT_DirData::DoCmdSort(const TDesC& aSection)
|
|
238 |
{
|
|
239 |
INFO_PRINTF1(_L("Sorting directory entries!"));
|
|
240 |
|
|
241 |
TPtrC sortKey;
|
|
242 |
|
|
243 |
if (GET_OPTIONAL_STRING_PARAMETER(KSortkey, aSection, sortKey))
|
|
244 |
{
|
|
245 |
TUint fixedKey = 0;
|
|
246 |
|
|
247 |
if ( !ConvertSortKeys(sortKey, fixedKey) )
|
|
248 |
{
|
|
249 |
ERR_PRINTF2(_L("Given sortkey (%S) is invalid"), &sortKey);
|
|
250 |
SetBlockResult(EFail);
|
|
251 |
}
|
|
252 |
|
|
253 |
TInt err = iDir->Sort(fixedKey);
|
|
254 |
|
|
255 |
if (err != KErrNone)
|
|
256 |
{
|
|
257 |
ERR_PRINTF2(_L("Directory entries have not been sorted! Error code = %d"), err);
|
|
258 |
SetError(err);
|
|
259 |
}
|
|
260 |
else
|
|
261 |
{
|
|
262 |
INFO_PRINTF1(_L("Directory entries have been sorted!"));
|
|
263 |
}
|
|
264 |
}
|
|
265 |
else
|
|
266 |
{
|
|
267 |
TInt numSortKey;
|
|
268 |
if (GET_MANDATORY_INT_PARAMETER(KNumSortkey, aSection, numSortKey))
|
|
269 |
{
|
|
270 |
TInt err = iDir->Sort(numSortKey);
|
|
271 |
|
|
272 |
if (err != KErrNone)
|
|
273 |
{
|
|
274 |
ERR_PRINTF2(_L("Directory entries has not been sorted! Error code = %d"), err);
|
|
275 |
SetError(err);
|
|
276 |
}
|
|
277 |
else
|
|
278 |
{
|
|
279 |
INFO_PRINTF1(_L("Directory entries has been sorted!"));
|
|
280 |
}
|
|
281 |
}
|
|
282 |
}
|
|
283 |
INFO_PRINTF1(_L("Results after sorting!"));
|
|
284 |
for (TInt i = 0; i < iDir->Count(); i++)
|
|
285 |
{
|
|
286 |
INFO_PRINTF3(_L("%d) %S"), i+1, &(*iDir)[i].iName);
|
|
287 |
}
|
|
288 |
}
|
|
289 |
|
|
290 |
TBool CT_DirData::ConvertSortKeys(TDesC &aConstantName, TUint& aSortKey)
|
|
291 |
{
|
|
292 |
|
|
293 |
TBool ret = ETrue;
|
|
294 |
|
|
295 |
if (aConstantName == KESortByName)
|
|
296 |
{
|
|
297 |
aSortKey = ESortByName;
|
|
298 |
}
|
|
299 |
else if (aConstantName == KESortByExt)
|
|
300 |
{
|
|
301 |
aSortKey = ESortByExt;
|
|
302 |
}
|
|
303 |
else if (aConstantName == KESortBySize)
|
|
304 |
{
|
|
305 |
aSortKey = ESortBySize;
|
|
306 |
}
|
|
307 |
else if (aConstantName == KESortByDate)
|
|
308 |
{
|
|
309 |
aSortKey = ESortByDate;
|
|
310 |
}
|
|
311 |
else if (aConstantName == KESortByUid)
|
|
312 |
{
|
|
313 |
aSortKey = ESortByUid;
|
|
314 |
}
|
|
315 |
else if (aConstantName == KEDirsAnyOrder)
|
|
316 |
{
|
|
317 |
aSortKey = EDirsAnyOrder;
|
|
318 |
}
|
|
319 |
else if (aConstantName == KEDirsFirst)
|
|
320 |
{
|
|
321 |
aSortKey = EDirsFirst;
|
|
322 |
}
|
|
323 |
else if (aConstantName == KEDirsLast)
|
|
324 |
{
|
|
325 |
aSortKey = EDirsLast;
|
|
326 |
}
|
|
327 |
else if (aConstantName == KEAscending)
|
|
328 |
{
|
|
329 |
aSortKey = EAscending;
|
|
330 |
}
|
|
331 |
else if (aConstantName == KEDescending)
|
|
332 |
{
|
|
333 |
aSortKey = EDescending;
|
|
334 |
}
|
|
335 |
else if (aConstantName == KEDirDescending)
|
|
336 |
{
|
|
337 |
aSortKey = EDirDescending;
|
|
338 |
}
|
|
339 |
else if (aConstantName == KESortNone)
|
|
340 |
{
|
|
341 |
aSortKey = ESortNone;
|
|
342 |
}
|
|
343 |
else
|
|
344 |
{
|
|
345 |
TInt location = aConstantName.Match(_L("*|*"));
|
|
346 |
if( location != KErrNotFound )
|
|
347 |
{
|
|
348 |
//Converting Left part of the data
|
|
349 |
TPtrC tempStr = aConstantName.Left(location);
|
|
350 |
ret = ConvertSortKeys(tempStr, aSortKey);
|
|
351 |
|
|
352 |
//Converting right data can be with another "|"
|
|
353 |
tempStr.Set(aConstantName.Mid(location + 1));
|
|
354 |
|
|
355 |
TUint tmp;
|
|
356 |
if ( ConvertSortKeys(tempStr, tmp) )
|
|
357 |
{
|
|
358 |
aSortKey |= tmp;
|
|
359 |
}
|
|
360 |
else
|
|
361 |
{
|
|
362 |
ret = EFalse;
|
|
363 |
}
|
|
364 |
}
|
|
365 |
}
|
|
366 |
|
|
367 |
return ret;
|
|
368 |
}
|