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