719
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
872
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
719
|
5 |
// which accompanies this distribution, and is available
|
872
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
719
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// This is the Cpp file which contains the utility functions common across the servers
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
/**
|
|
21 |
@file
|
|
22 |
*/
|
|
23 |
|
|
24 |
|
|
25 |
// User includes
|
|
26 |
#include <t_utils.h>
|
|
27 |
#include <t_utilscentralrepository.h>
|
|
28 |
|
|
29 |
// Epoc includes
|
|
30 |
#include <msvids.h>
|
|
31 |
#include <bautils.h>
|
|
32 |
#include <msvutils.h>
|
|
33 |
#include <barsc.h>
|
|
34 |
|
|
35 |
|
|
36 |
// Literals Used
|
|
37 |
const TInt KDefBufferSize = 1024;
|
|
38 |
|
|
39 |
|
|
40 |
/**
|
|
41 |
CT_MsgUtils()
|
|
42 |
Constructor
|
|
43 |
*/
|
|
44 |
EXPORT_C CT_MsgUtils::CT_MsgUtils()
|
|
45 |
{
|
|
46 |
}
|
|
47 |
|
|
48 |
|
|
49 |
/**
|
|
50 |
~CT_MsgUtils()
|
|
51 |
Constructor
|
|
52 |
*/
|
|
53 |
CT_MsgUtils::~CT_MsgUtils()
|
|
54 |
{
|
|
55 |
}
|
|
56 |
|
|
57 |
/**
|
|
58 |
OpenResourceFileL()
|
|
59 |
Opens a resource File
|
|
60 |
|
|
61 |
@param rFile
|
|
62 |
Resource File Handle
|
|
63 |
|
|
64 |
@param anFs
|
|
65 |
File Session associated
|
|
66 |
|
|
67 |
@param aFileName
|
|
68 |
The Name of resource File to be opened
|
|
69 |
*/
|
|
70 |
EXPORT_C void CT_MsgUtils::OpenResourceFileL(RResourceFile& rFile, RFs& anFs, const TDesC& aFileName )
|
|
71 |
{
|
|
72 |
// open resource file
|
|
73 |
TFileName fileName(aFileName);
|
|
74 |
MsvUtils::AddPathAndExtensionToResFileL(fileName);
|
|
75 |
BaflUtils::NearestLanguageFile( anFs, fileName );
|
|
76 |
if (BaflUtils::FileExists(anFs,fileName))
|
|
77 |
{
|
|
78 |
rFile.OpenL( anFs, fileName );
|
|
79 |
return;
|
|
80 |
}
|
|
81 |
User::Leave(KErrNotFound);
|
|
82 |
}
|
|
83 |
|
|
84 |
/**
|
|
85 |
CloseResourceFile()
|
|
86 |
Closes a recource File
|
|
87 |
|
|
88 |
@param aFile
|
|
89 |
The Name of resource File to be closed
|
|
90 |
*/
|
|
91 |
EXPORT_C void CT_MsgUtils::CloseResourceFile( TAny* aFile )
|
|
92 |
{
|
|
93 |
((RResourceFile*)aFile)->Close();
|
|
94 |
}
|
|
95 |
|
|
96 |
|
|
97 |
/**
|
|
98 |
FindEntryByNameL()
|
|
99 |
Search the entries under a given folder ID by name of the entry
|
|
100 |
i.e, iDescription or iDetails value of an entry
|
|
101 |
|
|
102 |
@param aSession
|
|
103 |
Session object
|
|
104 |
|
|
105 |
@param aParentId
|
|
106 |
Parent Id under which the entry needs to be found
|
|
107 |
|
|
108 |
@param aEntryName
|
|
109 |
The entry name that needs to be found
|
|
110 |
|
|
111 |
@leave KErrNotFound
|
|
112 |
Leaves if no entry's iDescription or iDetails matches with aEntryName
|
|
113 |
|
|
114 |
@return
|
|
115 |
Id of the entry that match
|
|
116 |
*/
|
|
117 |
EXPORT_C TMsvId CT_MsgUtils::FindEntryByNameL(CMsvSession* aSession, TMsvId aParentId, TDesC& aEntryName, TBool aCaseSensitive)
|
|
118 |
{
|
|
119 |
|
|
120 |
TMsvId msgEntryId = KMsvNullIndexEntryId;
|
|
121 |
|
|
122 |
// Set the context to the Parent
|
|
123 |
CMsvEntry* entry = CMsvEntry::NewL(*aSession, aParentId,TMsvSelectionOrdering
|
|
124 |
(KMsvNoGrouping,EMsvSortByNone, ETrue));
|
|
125 |
CleanupStack::PushL(entry);
|
|
126 |
|
|
127 |
entry->SetEntryL(aParentId);
|
|
128 |
|
|
129 |
msgEntryId = FindEntryByNameL(entry, aEntryName, aCaseSensitive);
|
|
130 |
|
|
131 |
CleanupStack::PopAndDestroy(entry);
|
|
132 |
|
|
133 |
return msgEntryId;
|
|
134 |
}
|
|
135 |
|
|
136 |
|
|
137 |
/**
|
|
138 |
FindEntryByNameL()
|
|
139 |
Search the entries under a given folder ID by name of the entry
|
|
140 |
i.e, iDescription or iDetails value of an entry
|
|
141 |
|
|
142 |
@param aSession
|
|
143 |
Session object
|
|
144 |
|
|
145 |
@param aParentId
|
|
146 |
Parent Id under which the entry needs to be found
|
|
147 |
|
|
148 |
@param aEntryName
|
|
149 |
The entry name that needs to be found
|
|
150 |
|
|
151 |
@param aParentEntryName
|
|
152 |
The Parent entry name that needs to be matched with the entry found
|
|
153 |
|
|
154 |
@leave KErrNotFound
|
|
155 |
Leaves if no entry's iDescription or iDetails matches with aEntryName
|
|
156 |
|
|
157 |
@return
|
|
158 |
Id of the entry that match
|
|
159 |
*/
|
|
160 |
EXPORT_C TMsvId CT_MsgUtils::FindEntryByNameL(CMsvSession* aSession, TMsvId aParentId, TDesC& aEntryName, TDesC& aParentEntryName, TBool aCaseSensitive)
|
|
161 |
{
|
|
162 |
|
|
163 |
TMsvId msgEntryId = KMsvNullIndexEntryId;
|
|
164 |
|
|
165 |
// Set the context to the Parent
|
|
166 |
CMsvEntry* entry = CMsvEntry::NewL(*aSession, aParentId,TMsvSelectionOrdering
|
|
167 |
(KMsvNoGrouping,EMsvSortByNone, ETrue));
|
|
168 |
CleanupStack::PushL(entry);
|
|
169 |
|
|
170 |
entry->SetEntryL(aParentId);
|
|
171 |
|
|
172 |
msgEntryId = FindEntryByNameL(entry, aEntryName, aParentEntryName, aCaseSensitive);
|
|
173 |
|
|
174 |
CleanupStack::PopAndDestroy(entry);
|
|
175 |
|
|
176 |
return msgEntryId;
|
|
177 |
}
|
|
178 |
|
|
179 |
|
|
180 |
/**
|
|
181 |
FindEntryByNameL()
|
|
182 |
Search the entries under a given entry(an object of CMsvEntry) by name of the entry
|
|
183 |
i.e, iDescription or iDetails value of an entry
|
|
184 |
|
|
185 |
@param aEntry
|
|
186 |
Parent entry under which the given entry needs to be searched
|
|
187 |
|
|
188 |
@param aEntryName
|
|
189 |
The entry name that needs to be found
|
|
190 |
|
|
191 |
@leave KErrNotFound
|
|
192 |
Leaves if no entry's iDescription or iDetails matches with aEntryName
|
|
193 |
|
|
194 |
@return
|
|
195 |
Id of the entry that match
|
|
196 |
*/
|
|
197 |
EXPORT_C TMsvId CT_MsgUtils::FindEntryByNameL(CMsvEntry* aEntry,TDesC& aEntryName, TBool aCaseSensitive)
|
|
198 |
{
|
|
199 |
TMsvId msgEntryId = KMsvNullIndexEntryId;
|
|
200 |
|
|
201 |
msgEntryId = RecFindEntryByNameL(*aEntry, aEntryName, aCaseSensitive);
|
|
202 |
|
|
203 |
if(msgEntryId == KMsvNullIndexEntryId)
|
|
204 |
{
|
|
205 |
User::Leave(KErrNotFound);
|
|
206 |
}
|
|
207 |
|
|
208 |
return msgEntryId;
|
|
209 |
}
|
|
210 |
|
|
211 |
|
|
212 |
/**
|
|
213 |
FindEntryByNameL()
|
|
214 |
Search the entries under a given entry(an object of CMsvEntry) by name of the entry
|
|
215 |
i.e, iDescription or iDetails value of an entry
|
|
216 |
|
|
217 |
@param aEntry
|
|
218 |
Parent entry under which the given entry needs to be searched
|
|
219 |
|
|
220 |
@param aEntryName
|
|
221 |
The entry name that needs to be found
|
|
222 |
|
|
223 |
@param aParentEntryName
|
|
224 |
The Parent entry name that needs to be matched with the entry found
|
|
225 |
|
|
226 |
@leave KErrNotFound
|
|
227 |
Leaves if no entry's iDescription or iDetails matches with aEntryName
|
|
228 |
|
|
229 |
@return
|
|
230 |
Id of the entry that match
|
|
231 |
*/
|
|
232 |
EXPORT_C TMsvId CT_MsgUtils::FindEntryByNameL(CMsvEntry* aEntry,TDesC& aEntryName, TDesC& aParentEntryName, TBool aCaseSensitive)
|
|
233 |
{
|
|
234 |
TMsvId msgEntryId = KMsvNullIndexEntryId;
|
|
235 |
|
|
236 |
msgEntryId = RecFindEntryByNameL(*aEntry, aEntryName, aParentEntryName, aCaseSensitive);
|
|
237 |
|
|
238 |
if(msgEntryId == KMsvNullIndexEntryId)
|
|
239 |
{
|
|
240 |
User::Leave(KErrNotFound);
|
|
241 |
}
|
|
242 |
|
|
243 |
return msgEntryId;
|
|
244 |
}
|
|
245 |
|
|
246 |
|
|
247 |
/**
|
|
248 |
RecFindEntryByNameL()
|
|
249 |
Recursively search the entries (including all sub entries) under a given entry (an object of CMsvEntry)
|
|
250 |
by name of the entry i.e, iDescription or iDetails value of an entry
|
|
251 |
|
|
252 |
@param aEntry
|
|
253 |
Parent entry under which the given entry needs to be searched
|
|
254 |
|
|
255 |
@param aEntryName
|
|
256 |
The entry name that needs to be found
|
|
257 |
|
|
258 |
@leave KErrNotFound
|
|
259 |
Leaves if no entry's iDescription or iDetails matches with aEntryName
|
|
260 |
|
|
261 |
@return
|
|
262 |
Id of the entry that match
|
|
263 |
*/
|
|
264 |
TMsvId CT_MsgUtils::RecFindEntryByNameL(CMsvEntry& aEntry, TDesC& aEntryName, TBool aCaseSensitive)
|
|
265 |
{
|
|
266 |
|
|
267 |
TMsvId msgEntryId = KMsvNullIndexEntryId;
|
|
268 |
|
|
269 |
CMsvEntrySelection* selection = aEntry.ChildrenL();
|
|
270 |
CleanupStack::PushL(selection);
|
|
271 |
// Search for the entry in the children selection, based on the entry name given
|
|
272 |
TBool found = EFalse;
|
|
273 |
TInt count = selection->Count();
|
|
274 |
for (TInt index = 0; (index<count) && (!found); index++)
|
|
275 |
{
|
|
276 |
// Set the context to the child entry
|
|
277 |
aEntry.SetEntryL((*selection)[index]);
|
|
278 |
|
|
279 |
if (aCaseSensitive)
|
|
280 |
{
|
|
281 |
if (( aEntryName.Compare( aEntry.Entry().iDescription ) == 0 ) ||
|
|
282 |
( aEntryName.Compare( aEntry.Entry().iDetails ) == 0 ))
|
|
283 |
{
|
|
284 |
found = ETrue;
|
|
285 |
}
|
|
286 |
}
|
|
287 |
else if (( aEntryName.CompareF( aEntry.Entry().iDescription ) == 0 ) ||
|
|
288 |
( aEntryName.CompareF( aEntry.Entry().iDetails ) == 0 ))
|
|
289 |
{
|
|
290 |
found = ETrue;
|
|
291 |
}
|
|
292 |
|
|
293 |
if (found)
|
|
294 |
{
|
|
295 |
msgEntryId = (*selection)[index];
|
|
296 |
}
|
|
297 |
else
|
|
298 |
{
|
|
299 |
CMsvEntry* nextEntry = CMsvEntry::NewL(aEntry.Session(), (*selection)[index],TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue));
|
|
300 |
CleanupStack::PushL(nextEntry);
|
|
301 |
|
|
302 |
msgEntryId = RecFindEntryByNameL(*nextEntry, aEntryName, aCaseSensitive);
|
|
303 |
if(msgEntryId != KMsvNullIndexEntryId)
|
|
304 |
{
|
|
305 |
found = ETrue;
|
|
306 |
}
|
|
307 |
CleanupStack::PopAndDestroy(nextEntry);
|
|
308 |
}
|
|
309 |
}
|
|
310 |
|
|
311 |
CleanupStack::PopAndDestroy(selection);
|
|
312 |
return msgEntryId;
|
|
313 |
}
|
|
314 |
|
|
315 |
|
|
316 |
/**
|
|
317 |
RecFindEntryByNameL()
|
|
318 |
Recursively search the entries (including all sub entries) under a given entry (an object of CMsvEntry)
|
|
319 |
by name of the entry i.e, iDescription or iDetails value of an entry
|
|
320 |
|
|
321 |
@param aEntry
|
|
322 |
Parent entry under which the given entry needs to be searched
|
|
323 |
|
|
324 |
@param aEntryName
|
|
325 |
The entry name that needs to be found
|
|
326 |
|
|
327 |
@param aParentEntryName
|
|
328 |
The Parent entry name that needs to be matched with the entry found
|
|
329 |
|
|
330 |
@leave KErrNotFound
|
|
331 |
Leaves if no entry's iDescription or iDetails matches with aEntryName
|
|
332 |
|
|
333 |
@return
|
|
334 |
Id of the entry that match
|
|
335 |
*/
|
|
336 |
TMsvId CT_MsgUtils::RecFindEntryByNameL(CMsvEntry& aEntry, TDesC& aEntryName, TDesC& aParentEntryName, TBool aCaseSensitive)
|
|
337 |
{
|
|
338 |
TMsvId msgEntryId = KMsvNullIndexEntryId;
|
|
339 |
|
|
340 |
CMsvEntrySelection* selection = aEntry.ChildrenL();
|
|
341 |
CleanupStack::PushL(selection);
|
|
342 |
// Search for the entry in the children selection, based on the entry name given
|
|
343 |
TBool found = EFalse;
|
|
344 |
TInt count = selection->Count();
|
|
345 |
TBool matched = EFalse;
|
|
346 |
|
|
347 |
for (TInt index = 0; (index<count) && (!found); index++)
|
|
348 |
{
|
|
349 |
// Set the context to the child entry
|
|
350 |
aEntry.SetEntryL((*selection)[index]);
|
|
351 |
|
|
352 |
matched = EFalse;
|
|
353 |
|
|
354 |
if (aCaseSensitive)
|
|
355 |
{
|
|
356 |
if (( aEntryName.Compare( aEntry.Entry().iDescription ) == 0 ) ||
|
|
357 |
( aEntryName.Compare( aEntry.Entry().iDetails ) == 0 ))
|
|
358 |
{
|
|
359 |
matched = ETrue;
|
|
360 |
}
|
|
361 |
}
|
|
362 |
else if (( aEntryName.CompareF( aEntry.Entry().iDescription ) == 0 ) ||
|
|
363 |
( aEntryName.CompareF( aEntry.Entry().iDetails ) == 0 ))
|
|
364 |
{
|
|
365 |
matched = ETrue;
|
|
366 |
}
|
|
367 |
|
|
368 |
if (matched)
|
|
369 |
{
|
|
370 |
//Check Parent
|
|
371 |
CMsvEntry* parentEntry = CMsvEntry::NewL(aEntry.Session(), aEntry.Entry().Parent(),TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue));
|
|
372 |
CleanupStack::PushL(parentEntry);
|
|
373 |
|
|
374 |
if(CheckParent(*parentEntry,aParentEntryName))
|
|
375 |
{
|
|
376 |
found = ETrue;
|
|
377 |
msgEntryId = (*selection)[index];
|
|
378 |
}
|
|
379 |
CleanupStack::PopAndDestroy(parentEntry);
|
|
380 |
}
|
|
381 |
|
|
382 |
if (!found)
|
|
383 |
{
|
|
384 |
CMsvEntry* nextEntry = CMsvEntry::NewL(aEntry.Session(), (*selection)[index],TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue));
|
|
385 |
CleanupStack::PushL(nextEntry);
|
|
386 |
|
|
387 |
msgEntryId = RecFindEntryByNameL(*nextEntry, aEntryName, aParentEntryName, aCaseSensitive);
|
|
388 |
if(msgEntryId != KMsvNullIndexEntryId)
|
|
389 |
{
|
|
390 |
found = ETrue;
|
|
391 |
}
|
|
392 |
CleanupStack::PopAndDestroy(nextEntry);
|
|
393 |
}
|
|
394 |
}
|
|
395 |
|
|
396 |
CleanupStack::PopAndDestroy(selection);
|
|
397 |
return msgEntryId;
|
|
398 |
}
|
|
399 |
|
|
400 |
|
|
401 |
/**
|
|
402 |
CheckParent()
|
|
403 |
Checks if the given parent name matches the name of the given parent entry
|
|
404 |
|
|
405 |
@param aParentEntry
|
|
406 |
Parent entry whose name is to be checked
|
|
407 |
|
|
408 |
@param aParentEntryName
|
|
409 |
The Parent entry name that we are checking against
|
|
410 |
|
|
411 |
@return
|
|
412 |
ETrue if they match and EFalse if they do not
|
|
413 |
*/
|
|
414 |
TBool CT_MsgUtils::CheckParent(CMsvEntry& aParentEntry, TDesC& aParentEntryName)
|
|
415 |
{
|
|
416 |
|
|
417 |
TBool ret = EFalse;
|
|
418 |
|
|
419 |
if (( aParentEntryName.CompareF( aParentEntry.Entry().iDescription ) == 0 ) ||
|
|
420 |
( aParentEntryName.CompareF( aParentEntry.Entry().iDetails ) == 0 ))
|
|
421 |
{
|
|
422 |
ret = ETrue;
|
|
423 |
}
|
|
424 |
|
|
425 |
return ret;
|
|
426 |
}
|
|
427 |
|
|
428 |
|
|
429 |
/**
|
|
430 |
CreateChildrenSelectionL()
|
|
431 |
This function creates a selection of the children entries under a given parent Id
|
|
432 |
|
|
433 |
@param aSession
|
|
434 |
A CMsvSession object
|
|
435 |
|
|
436 |
@param aEntryId
|
|
437 |
Id of the entry
|
|
438 |
|
|
439 |
@return
|
|
440 |
Returns a selection of all child entries under the given entry
|
|
441 |
*/
|
|
442 |
EXPORT_C CMsvEntrySelection* CT_MsgUtils::CreateChildrenSelectionL(CMsvSession* aSession,
|
|
443 |
TMsvId aEntryId)
|
|
444 |
{
|
|
445 |
CMsvEntry* entry = CMsvEntry::NewL(*aSession, aEntryId,TMsvSelectionOrdering
|
|
446 |
( KMsvNoGrouping,EMsvSortByNone, ETrue));
|
|
447 |
CleanupStack::PushL(entry);
|
|
448 |
entry->SetEntryL(aEntryId);
|
|
449 |
|
|
450 |
TMsvSelectionOrdering order;
|
|
451 |
order.SetShowInvisibleEntries(ETrue);
|
|
452 |
entry->SetSortTypeL(order);
|
|
453 |
|
|
454 |
CMsvEntrySelection* selection = entry->ChildrenL();
|
|
455 |
CleanupStack::PopAndDestroy(entry);
|
|
456 |
|
|
457 |
return selection;
|
|
458 |
}
|
|
459 |
|
|
460 |
/**
|
|
461 |
CreateChildrenSelectionWithTypeL()
|
|
462 |
This function creates a selection of the children entries under a given parent Id
|
|
463 |
which are of a specified type.
|
|
464 |
|
|
465 |
@param aSession
|
|
466 |
A CMsvSession object
|
|
467 |
|
|
468 |
@param aEntryId
|
|
469 |
Id of the entry
|
|
470 |
|
|
471 |
@param aType
|
|
472 |
Type of entry to look for
|
|
473 |
|
|
474 |
@return
|
|
475 |
Returns a selection of all child entries under the given entry of the specified type
|
|
476 |
*/
|
|
477 |
EXPORT_C CMsvEntrySelection* CT_MsgUtils::CreateChildrenSelectionWithTypeL(CMsvSession* aSession, TMsvId aEntryId, TUid aType)
|
|
478 |
{
|
|
479 |
CMsvEntry* entry = CMsvEntry::NewL(*aSession, aEntryId, TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue));
|
|
480 |
CleanupStack::PushL(entry);
|
|
481 |
entry->SetEntryL(aEntryId);
|
|
482 |
|
|
483 |
TMsvSelectionOrdering order;
|
|
484 |
order.SetShowInvisibleEntries(ETrue);
|
|
485 |
entry->SetSortTypeL(order);
|
|
486 |
|
|
487 |
CMsvEntrySelection* selection = entry->ChildrenWithTypeL(aType);
|
|
488 |
CleanupStack::PopAndDestroy(entry);
|
|
489 |
|
|
490 |
return selection;
|
|
491 |
}
|
|
492 |
|
|
493 |
|
|
494 |
/**
|
|
495 |
CreateChildrenSelectionRemoteFolderL()
|
|
496 |
This function creates a selection of the child entries under the
|
|
497 |
remote folder Id if the service name is specified
|
|
498 |
|
|
499 |
@param aSession
|
|
500 |
A CMsvSession object
|
|
501 |
|
|
502 |
@param aAccountName
|
|
503 |
The account name or service name
|
|
504 |
|
|
505 |
@param aFolderName
|
|
506 |
The name of the remote folder whose entries need to be fetched
|
|
507 |
|
|
508 |
@return
|
|
509 |
The selection of all entries under the given entry
|
|
510 |
*/
|
|
511 |
EXPORT_C CMsvEntrySelection* CT_MsgUtils::CreateChildrenSelectionRemoteFolderL(CMsvSession*
|
|
512 |
aSession,TPtrC aAccountName,TPtrC aFolderName)
|
|
513 |
{
|
|
514 |
TMsvId remoteFolderId = GetRemoteFolderIdByNameL(aSession, aAccountName, aFolderName);
|
|
515 |
return CreateChildrenSelectionL(aSession,remoteFolderId);
|
|
516 |
}
|
|
517 |
|
|
518 |
/**
|
|
519 |
CreateChildrenSelectionRemoteFolderWithTypeL()
|
|
520 |
This function creates a selection of the child entries under the
|
|
521 |
remote folder Id with a specified type if the service name is specified
|
|
522 |
|
|
523 |
@param aSession
|
|
524 |
A CMsvSession object
|
|
525 |
|
|
526 |
@param aAccountName
|
|
527 |
The account name or service name
|
|
528 |
|
|
529 |
@param aFolderName
|
|
530 |
The name of the remote folder whose entries need to be fetched
|
|
531 |
|
|
532 |
@param aType
|
|
533 |
Type of entry to look for
|
|
534 |
|
|
535 |
@return
|
|
536 |
The selection of all entries under the given entry with the specified type
|
|
537 |
*/
|
|
538 |
EXPORT_C CMsvEntrySelection* CT_MsgUtils::CreateChildrenSelectionRemoteFolderWithTypeL(CMsvSession*
|
|
539 |
aSession,TPtrC aAccountName,TPtrC aFolderName, TUid aType)
|
|
540 |
{
|
|
541 |
TMsvId remoteFolderId = GetRemoteFolderIdByNameL(aSession, aAccountName, aFolderName);
|
|
542 |
return CreateChildrenSelectionWithTypeL(aSession, remoteFolderId, aType);
|
|
543 |
}
|
|
544 |
|
|
545 |
|
|
546 |
/**
|
|
547 |
GetRemoteFolderIdByNameL()
|
|
548 |
Searches for a given entry under the remote folder Id specified and gets it Id
|
|
549 |
|
|
550 |
@param aSession
|
|
551 |
A CMsvSession object
|
|
552 |
|
|
553 |
@param aAccountName
|
|
554 |
The account name
|
|
555 |
|
|
556 |
@param aFolderName
|
|
557 |
The name of the remote folder whose Id is to be found
|
|
558 |
|
|
559 |
@return
|
|
560 |
The Id of the specified folder
|
|
561 |
*/
|
|
562 |
EXPORT_C TMsvId CT_MsgUtils::GetRemoteFolderIdByNameL(CMsvSession* aSession,TPtrC aAccountName,TPtrC aFolderName, TBool aCaseSensitive)
|
|
563 |
{
|
|
564 |
TMsvId imapServiceId = CT_MsgUtilsCentralRepository::GetImapServiceIdL((TDes&)aAccountName);
|
|
565 |
return CT_MsgUtils::FindEntryByNameL(aSession, imapServiceId, (TDesC&)aFolderName, aCaseSensitive);
|
|
566 |
}
|
|
567 |
|
|
568 |
|
|
569 |
/**
|
|
570 |
GetRemoteFolderIdByNameL()
|
|
571 |
Searches for a given entry under the remote folder Id specified and gets it Id
|
|
572 |
|
|
573 |
@param aSession
|
|
574 |
A CMsvSession object
|
|
575 |
|
|
576 |
@param aAccountName
|
|
577 |
The account name
|
|
578 |
|
|
579 |
@param aFolderName
|
|
580 |
The name of the remote folder whose Id is to be found
|
|
581 |
|
|
582 |
@param aFolderName
|
|
583 |
The name of the remote parent folder of the entry to be found
|
|
584 |
|
|
585 |
@return
|
|
586 |
The Id of the specified folder
|
|
587 |
*/
|
|
588 |
EXPORT_C TMsvId CT_MsgUtils::GetRemoteFolderIdByNameL(CMsvSession* aSession,TPtrC aAccountName,TPtrC aFolderName, TPtrC aParentFolderName, TBool aCaseSensitive)
|
|
589 |
{
|
|
590 |
TMsvId imapServiceId = CT_MsgUtilsCentralRepository::GetImapServiceIdL((TDes&)aAccountName);
|
|
591 |
return CT_MsgUtils::FindEntryByNameL(aSession, imapServiceId, (TDesC&)aFolderName, (TDesC&)aParentFolderName, aCaseSensitive);
|
|
592 |
}
|
|
593 |
|
|
594 |
|
|
595 |
/**
|
|
596 |
SearchMessageBySubjectL()
|
|
597 |
This function searches for a message based on the
|
|
598 |
subject under the specified local folder
|
|
599 |
|
|
600 |
@param aSession
|
|
601 |
A CMsvSession object
|
|
602 |
|
|
603 |
@param afolderId
|
|
604 |
The folder Id under which the search needs to be done
|
|
605 |
|
|
606 |
@param aSubject
|
|
607 |
The subject name of the message
|
|
608 |
|
|
609 |
@leave KErrNotFound
|
|
610 |
Leaves if the message is not found
|
|
611 |
|
|
612 |
@return
|
|
613 |
If the message is found it returns the message Id
|
|
614 |
*/
|
|
615 |
EXPORT_C TMsvId CT_MsgUtils::SearchMessageBySubjectL(CMsvSession* aSession,TMsvId afolderId,TPtrC aSubject)
|
|
616 |
{
|
|
617 |
TMsvId messageId = KMsvNullIndexEntryId;
|
|
618 |
|
|
619 |
CMsvEntry* entry = aSession->GetEntryL(afolderId);
|
|
620 |
CleanupStack::PushL(entry);
|
|
621 |
|
|
622 |
// Set the entry to the source folder id
|
|
623 |
entry->SetEntryL(afolderId);
|
|
624 |
|
|
625 |
//Get CMsvEntrySelection object
|
|
626 |
CMsvEntrySelection* selection = entry->ChildrenL();
|
|
627 |
CleanupStack::PushL(selection);
|
|
628 |
|
|
629 |
TInt count = selection->Count();
|
|
630 |
|
|
631 |
if ( count > 0)
|
|
632 |
{
|
|
633 |
CMsvEntry* childEntry = aSession->GetEntryL(selection->At(0));
|
|
634 |
CleanupStack::PushL(childEntry);
|
|
635 |
|
|
636 |
for(TInt entryIndex = 0 ; entryIndex< count; entryIndex++)
|
|
637 |
{
|
|
638 |
childEntry->SetEntryL(selection->At(entryIndex));
|
|
639 |
|
|
640 |
if (childEntry->Entry().iDescription.Compare(aSubject) == 0)
|
|
641 |
{
|
|
642 |
messageId = selection->At(entryIndex);
|
|
643 |
break;
|
|
644 |
}
|
|
645 |
}
|
|
646 |
CleanupStack::PopAndDestroy(childEntry);
|
|
647 |
}
|
|
648 |
if(messageId == KMsvNullIndexEntryId)
|
|
649 |
{
|
|
650 |
User::Leave(KErrNotFound);
|
|
651 |
}
|
|
652 |
CleanupStack::PopAndDestroy(2,entry); //selection,entry
|
|
653 |
return messageId;
|
|
654 |
}
|
|
655 |
|
|
656 |
/**
|
|
657 |
SearchMessageBySubjectL()
|
|
658 |
This function searches for a message based on the subject
|
|
659 |
under the specified local folder. This fucntion provides the
|
|
660 |
flexibility of making the invisible children entries visible.
|
|
661 |
|
|
662 |
@param aSession
|
|
663 |
A CMsvSession object
|
|
664 |
|
|
665 |
@param afolderId
|
|
666 |
The folder Id under which the search needs to be done
|
|
667 |
|
|
668 |
@param aSubject
|
|
669 |
The subject name of the message
|
|
670 |
|
|
671 |
@leave KErrNotFound
|
|
672 |
Leaves if the message is not found
|
|
673 |
|
|
674 |
@return
|
|
675 |
If the message is found it returns the message Id
|
|
676 |
*/
|
|
677 |
EXPORT_C TMsvId CT_MsgUtils::SearchMessageBySubjectL(CMsvSession* aSession,TMsvId afolderId,TPtrC aSubject, TBool aVisibleFlag)
|
|
678 |
{
|
|
679 |
TMsvId messageId = KMsvNullIndexEntryId;
|
|
680 |
|
|
681 |
CMsvEntry* entry = aSession->GetEntryL(afolderId);
|
|
682 |
CleanupStack::PushL(entry);
|
|
683 |
|
|
684 |
// Set the entry to the source folder id
|
|
685 |
entry->SetEntryL(afolderId);
|
|
686 |
if(aVisibleFlag)
|
|
687 |
{
|
|
688 |
// Make the message entries visible
|
|
689 |
TMsvSelectionOrdering order;
|
|
690 |
order.SetShowInvisibleEntries(ETrue);
|
|
691 |
entry->SetSortTypeL(order);
|
|
692 |
}
|
|
693 |
|
|
694 |
//Get CMsvEntrySelection object
|
|
695 |
CMsvEntrySelection* selection = entry->ChildrenL();
|
|
696 |
CleanupStack::PushL(selection);
|
|
697 |
|
|
698 |
TInt count = selection->Count();
|
|
699 |
|
|
700 |
if ( count > 0)
|
|
701 |
{
|
|
702 |
CMsvEntry* childEntry = aSession->GetEntryL(selection->At(0));
|
|
703 |
CleanupStack::PushL(childEntry);
|
|
704 |
|
|
705 |
for(TInt entryIndex = 0 ; entryIndex< count; entryIndex++)
|
|
706 |
{
|
|
707 |
childEntry->SetEntryL(selection->At(entryIndex));
|
|
708 |
|
|
709 |
if (childEntry->Entry().iDescription.Compare(aSubject) == 0)
|
|
710 |
{
|
|
711 |
messageId = selection->At(entryIndex);
|
|
712 |
break;
|
|
713 |
}
|
|
714 |
}
|
|
715 |
CleanupStack::PopAndDestroy(childEntry);
|
|
716 |
}
|
|
717 |
if(messageId == KMsvNullIndexEntryId)
|
|
718 |
{
|
|
719 |
User::Leave(KErrNotFound);
|
|
720 |
}
|
|
721 |
CleanupStack::PopAndDestroy(2,entry); //selection,entry
|
|
722 |
return messageId;
|
|
723 |
}
|
|
724 |
|
|
725 |
/**
|
|
726 |
CompareFilesL()
|
|
727 |
Compares two input files (ASCII & Unicode).
|
|
728 |
|
|
729 |
@param aFileOne
|
|
730 |
The first file to be compared
|
|
731 |
|
|
732 |
@param aFileTwo
|
|
733 |
The second file to be compared
|
|
734 |
|
|
735 |
@param aIsUnicode
|
|
736 |
To check if its unicode
|
|
737 |
|
|
738 |
@param aIgnoreCharList
|
|
739 |
An array of type CArrayFixFlat
|
|
740 |
|
|
741 |
@param aDiffFlag
|
|
742 |
Flag to indicate the difference
|
|
743 |
|
|
744 |
@return
|
|
745 |
Returns ETrue if the files are different.
|
|
746 |
*/
|
|
747 |
EXPORT_C TInt CT_MsgUtils::CompareFilesL(TPtrC aFileOne, TPtrC aFileTwo, TBool aIsUnicode,
|
|
748 |
CArrayFixFlat<TUint16>* aIgnoreCharList, TBool& aDiffFlag)
|
|
749 |
{
|
|
750 |
// Return Code
|
|
751 |
TInt retCode = KErrNone;
|
|
752 |
|
|
753 |
// Streams for the file1 and file2 to compare
|
|
754 |
RFileReadStream fileReadStream1;
|
|
755 |
RFileReadStream fileReadStream2;
|
|
756 |
|
|
757 |
// Files difference flag
|
|
758 |
aDiffFlag = EFalse;
|
|
759 |
|
|
760 |
RFs iFs;
|
|
761 |
User::LeaveIfError(iFs.Connect());
|
|
762 |
|
|
763 |
// Open file one to compare in the read only mode
|
|
764 |
retCode = fileReadStream1.Open( iFs, aFileOne, EFileShareReadersOnly);
|
|
765 |
|
|
766 |
// If the file open of the first file is successful then open the second file, also in read only mode
|
|
767 |
if(retCode == KErrNone)
|
|
768 |
{
|
|
769 |
retCode = fileReadStream2.Open( iFs, aFileTwo, EFileShareReadersOnly);
|
|
770 |
|
|
771 |
// The file open of the second file is successful
|
|
772 |
if(retCode == KErrNone)
|
|
773 |
{
|
|
774 |
// To hold the line content of file one
|
|
775 |
HBufC* lineOneBuffer = HBufC::NewLC(KDefBufferSize);
|
|
776 |
TPtr ptrLineOne = lineOneBuffer->Des();
|
|
777 |
|
|
778 |
// To hold the line content of file two
|
|
779 |
HBufC* lineTwoBuffer = HBufC::NewLC(KDefBufferSize);
|
|
780 |
TPtr ptrLineTwo = lineTwoBuffer->Des();
|
|
781 |
|
|
782 |
// End of File indicators
|
|
783 |
TBool eofOne = EFalse;
|
|
784 |
TBool eofTwo = EFalse;
|
|
785 |
|
|
786 |
// Read the file one and file two data
|
|
787 |
do
|
|
788 |
{
|
|
789 |
// Read file one data
|
|
790 |
eofOne = ReadDataL(fileReadStream1, ptrLineOne, aIsUnicode, aIgnoreCharList);
|
|
791 |
|
|
792 |
// Read file two data
|
|
793 |
eofTwo = ReadDataL(fileReadStream2, ptrLineTwo, aIsUnicode, aIgnoreCharList);
|
|
794 |
|
|
795 |
// Check EOF state of the files.
|
|
796 |
// Either both the files will be in EOF state or
|
|
797 |
// none of the files will be in EOF state
|
|
798 |
if((!eofOne && !eofTwo)||(eofOne && eofTwo))
|
|
799 |
{
|
|
800 |
// Compare the read lines from file one and the file two
|
|
801 |
if(ptrLineOne.Compare(ptrLineTwo) != 0)
|
|
802 |
{
|
|
803 |
// Different data content so set the differnce flag
|
|
804 |
aDiffFlag = ETrue;
|
|
805 |
}
|
|
806 |
}
|
|
807 |
else
|
|
808 |
{
|
|
809 |
// Different EOF
|
|
810 |
aDiffFlag = ETrue;
|
|
811 |
}
|
|
812 |
} while(!eofOne && !eofTwo && !aDiffFlag);
|
|
813 |
|
|
814 |
// Delete line buffers
|
|
815 |
CleanupStack::PopAndDestroy(2, lineOneBuffer);
|
|
816 |
}
|
|
817 |
}
|
|
818 |
|
|
819 |
// Close the open streams
|
|
820 |
fileReadStream1.Close();
|
|
821 |
fileReadStream2.Close();
|
|
822 |
|
|
823 |
iFs.Close();
|
|
824 |
// Return the difference flag
|
|
825 |
return retCode;
|
|
826 |
}
|
|
827 |
|
|
828 |
|
|
829 |
/**
|
|
830 |
ReadDataL()
|
|
831 |
Reads data chunk from the file stream. Returns ETrue if the EOF found
|
|
832 |
|
|
833 |
@param aFileReadStream
|
|
834 |
File Stream
|
|
835 |
|
|
836 |
@param aPtrLineBuffer
|
|
837 |
Buffer to hold a line
|
|
838 |
|
|
839 |
@param aIsUnicode
|
|
840 |
To check if its unicode
|
|
841 |
|
|
842 |
@param aIgnoreCharList
|
|
843 |
List of the characters to be ignored
|
|
844 |
|
|
845 |
@leave KErrNotFound
|
|
846 |
Leaves if aIgnoreCharList is empty
|
|
847 |
|
|
848 |
@return
|
|
849 |
Return end of file flag
|
|
850 |
*/
|
|
851 |
EXPORT_C TBool CT_MsgUtils::ReadDataL(RFileReadStream& aFileReadStream,
|
|
852 |
TPtr& aPtrLineBuffer, TBool aIsUnicode, CArrayFixFlat<TUint16>* aIgnoreCharList)
|
|
853 |
{
|
|
854 |
TUint16 element = 0;
|
|
855 |
TKeyArrayFix key(0, ECmpTUint16);
|
|
856 |
TInt charPosition = 0;
|
|
857 |
TBool eof = EFalse;
|
|
858 |
TInt errorCode = KErrNone;
|
|
859 |
TUint8 aCharASCII = 0;
|
|
860 |
|
|
861 |
aPtrLineBuffer.FillZ();
|
|
862 |
aPtrLineBuffer.SetLength(0);
|
|
863 |
|
|
864 |
// Validate the input ignore char list
|
|
865 |
if (!aIgnoreCharList)
|
|
866 |
{
|
|
867 |
// Invalid parameter passed to ReadDataL: No ignore char list passed
|
|
868 |
User::Leave(KErrNotFound);
|
|
869 |
}
|
|
870 |
|
|
871 |
// Read data from file and store it in lineBuffer
|
|
872 |
do
|
|
873 |
{
|
|
874 |
if(aIsUnicode)
|
|
875 |
{
|
|
876 |
TRAP(errorCode, (element = aFileReadStream.ReadUint16L()));
|
|
877 |
}
|
|
878 |
else
|
|
879 |
{
|
|
880 |
TRAP(errorCode, (aCharASCII = aFileReadStream.ReadUint8L()));
|
|
881 |
element = (TUint16) aCharASCII;
|
|
882 |
}
|
|
883 |
|
|
884 |
if (errorCode != KErrEof)
|
|
885 |
{
|
|
886 |
// Check the availability of ignore char in the array
|
|
887 |
if ( aIgnoreCharList->Find(element, key, charPosition) != KErrNone )
|
|
888 |
{
|
|
889 |
// Append the char to the buffer if the read char is not ignore char
|
|
890 |
aPtrLineBuffer.Append(element);
|
|
891 |
}
|
|
892 |
}
|
|
893 |
else
|
|
894 |
{
|
|
895 |
eof = ETrue;
|
|
896 |
break;
|
|
897 |
}
|
|
898 |
|
|
899 |
// Stop at the end of line or no more data
|
|
900 |
} while(aPtrLineBuffer.Length() < KDefBufferSize);
|
|
901 |
|
|
902 |
// Return end of file flag
|
|
903 |
return eof;
|
|
904 |
}
|