|
1 |
|
2 // Copyright (c) 2007-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 "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 #include <msvsearchsortquery.h> |
|
18 #include <msvids.h> |
|
19 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
20 #include "msvsearchsortconstants.h" |
|
21 #include "msvconsts.h" |
|
22 #endif |
|
23 /** |
|
24 Factory function which returns a pointer of CMsvSearchSortQuery to create a search-sort query. |
|
25 @param NONE |
|
26 @return If the function succeeds, this is a pointer to a newly allocated |
|
27 and initialised object. |
|
28 @leave KErrNoMemory A memory allocation failed |
|
29 */ |
|
30 EXPORT_C CMsvSearchSortQuery* CMsvSearchSortQuery::NewL() |
|
31 { |
|
32 CMsvSearchSortQuery* self = NewLC(); |
|
33 CleanupStack::Pop(); |
|
34 return self; |
|
35 } |
|
36 |
|
37 |
|
38 /** |
|
39 Factory function which returns a pointer of CMsvSearchSortQuery to create a search-sort query. |
|
40 @param NONE |
|
41 @return If the function succeeds, this is a pointer to a newly allocated |
|
42 and initialised object. |
|
43 @leave KErrNoMemory A memory allocation failed |
|
44 */ |
|
45 EXPORT_C CMsvSearchSortQuery* CMsvSearchSortQuery::NewLC() |
|
46 { |
|
47 CMsvSearchSortQuery* self = new(ELeave) CMsvSearchSortQuery(); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 /** |
|
54 Second phase construction, allocating memory for query table. |
|
55 @leave KErrNoMemory A memory allocation failed |
|
56 */ |
|
57 void CMsvSearchSortQuery::ConstructL() |
|
58 { |
|
59 iQueryTable = new(ELeave) TMsvQueryTable[KMaxLevelOfSearchAndSort]; |
|
60 } |
|
61 |
|
62 |
|
63 /** |
|
64 Constructor |
|
65 */ |
|
66 CMsvSearchSortQuery::CMsvSearchSortQuery() |
|
67 { |
|
68 iParentId = KMsvGlobalInBoxIndexEntryId; |
|
69 iCaseSensitive = EFalse; |
|
70 iWholeWord = EFalse; |
|
71 iWildCardCharacter = EFalse; |
|
72 iExplicitSort = EFalse; |
|
73 iIsSearchQuery = EFalse; |
|
74 iSubFolderSearch = EFalse; |
|
75 iQueryCount = 0; |
|
76 //if sort is not provided by query, there won't any sorting. so it's assigned to '0' |
|
77 iSortOnMessagePart = TMsvMessagePart(0); |
|
78 iSortOrder = EMsvSortAscending; |
|
79 iSearchSortResultType = EMsvResultAsTMsvId; |
|
80 iCountMultilevelSort = 0; |
|
81 iQueryId = 0; |
|
82 } |
|
83 |
|
84 /** |
|
85 Destructor. |
|
86 */ |
|
87 EXPORT_C CMsvSearchSortQuery::~CMsvSearchSortQuery() |
|
88 { |
|
89 //delete iQueryTable |
|
90 delete [] iQueryTable; |
|
91 } |
|
92 |
|
93 /** |
|
94 set aParentId. search and/or sort will be done this aParentId. |
|
95 @param aParentId Search and/or sort operation can be performed on a specified root, folder or service. |
|
96 */ |
|
97 EXPORT_C void CMsvSearchSortQuery::SetParentId(const TMsvId aParentId) |
|
98 { |
|
99 iParentId = aParentId; |
|
100 } |
|
101 |
|
102 /** |
|
103 Set Case Sensitive search option. |
|
104 @param aFlag set ETrue or EFalse |
|
105 */ |
|
106 EXPORT_C void CMsvSearchSortQuery::SetCaseSensitiveOption (TBool aCaseSensitive) |
|
107 { |
|
108 iCaseSensitive = aCaseSensitive; |
|
109 } |
|
110 |
|
111 /** |
|
112 Set Whole word search option. |
|
113 @param aFlag set ETrue or EFalse |
|
114 */ |
|
115 EXPORT_C void CMsvSearchSortQuery::SetWholeWord (TBool aWholeWord) |
|
116 { |
|
117 iWholeWord = aWholeWord; |
|
118 } |
|
119 |
|
120 /** |
|
121 Enable wild card character search. |
|
122 @param aFlag set ETrue or EFalse |
|
123 */ |
|
124 EXPORT_C void CMsvSearchSortQuery::SetWildCardSearch (TBool aWildCard) |
|
125 { |
|
126 iWildCardCharacter = aWildCard; |
|
127 } |
|
128 |
|
129 /** |
|
130 Client expects search sort results as TMsvId or TMsvEntry |
|
131 @param aResultType set result type as TMsvId or TMsvEntry |
|
132 */ |
|
133 |
|
134 EXPORT_C void CMsvSearchSortQuery::SetResultType (TMsvSearchSortResultType aSearchSortResultType) |
|
135 { |
|
136 iSearchSortResultType = aSearchSortResultType; |
|
137 } |
|
138 |
|
139 /** |
|
140 Enable subfolder search. |
|
141 @param aFlag set ETrue or EFalse |
|
142 */ |
|
143 EXPORT_C void CMsvSearchSortQuery::SetSubFolderSearch (TBool aSubFolderSearch) |
|
144 { |
|
145 iSubFolderSearch = aSubFolderSearch; |
|
146 } |
|
147 |
|
148 |
|
149 /** |
|
150 Adds the search options to the search-sort query. |
|
151 This function is used when the message part requires descriptor value during |
|
152 search-sort operation. |
|
153 |
|
154 @param aMsgPart A message part on which search operation has to be performed |
|
155 for all the messages under a particular folder entry |
|
156 @param aQueryDesValue The corresponding value of the message part that needs to be searched |
|
157 @param aRelOp An enumeration corresponding to a relational operator used against a |
|
158 particular message part for all the messages in a particular folder during |
|
159 the search operation |
|
160 @return None |
|
161 @leave KErrNone - Query is added successfully to search-sort query |
|
162 |
|
163 KErrArgument - An invalid value is passed for a particular message part |
|
164 |
|
165 KErrMsvInvalidOperator - An invalid operation is being performed |
|
166 on a particular message part |
|
167 |
|
168 KErrMsvQueryMaxLimit - An addition of search-sort operation has lead to a condition |
|
169 where the query options have exceeded the maximum number of search-sort options |
|
170 supported by messaging framework. The maximum search options that can be added |
|
171 to a search-sort query is ‘five’ and the maximum sort option that can be can be |
|
172 added is ‘one’ |
|
173 |
|
174 KErrQueryTooBig - The search-sort query is too big to be executed. |
|
175 This could be due to a bigger value for the search-sort option provided as part of |
|
176 the query. The query value added to a particular option is greater then KMsvMaxFindTextLength( = 300) |
|
177 */ |
|
178 EXPORT_C void CMsvSearchSortQuery::AddSearchOptionL (TMsvMessagePart aMsgPart, const TDesC& aQueryDesValue, TMsvRelationOp aRelOp) |
|
179 { |
|
180 //if query string is too big |
|
181 if( aQueryDesValue.Length() >= KMsvMaxSearchTextLength) |
|
182 { |
|
183 User::Leave(KErrQueryTooBig); |
|
184 } |
|
185 |
|
186 //if query string is empty |
|
187 if( aQueryDesValue.Length() <= 0) |
|
188 { |
|
189 User::Leave(KErrArgument); |
|
190 } |
|
191 |
|
192 //check whether it's reached maximum query limit |
|
193 if(iQueryCount >= KMaxLevelOfSearchAndSort) |
|
194 { |
|
195 User::Leave(KErrMsvQueryMaxLimit); |
|
196 } |
|
197 |
|
198 // validate the query sent by client, before storing into the query structure. |
|
199 User::LeaveIfError(ValidateQueryString(aMsgPart, aQueryDesValue, aRelOp)); |
|
200 |
|
201 iIsSearchQuery = ETrue; |
|
202 iQueryTable[iQueryCount].iQueryString.Copy(aQueryDesValue); |
|
203 iQueryTable[iQueryCount].iMessagePart = aMsgPart; |
|
204 iQueryTable[iQueryCount].iRelationOp = aRelOp; |
|
205 iQueryCount++; |
|
206 } |
|
207 |
|
208 /** |
|
209 Adds the search options to the search-sort query. |
|
210 This function is used when the message part requires integer value during |
|
211 search-sort operation |
|
212 |
|
213 @param aMsgPart A message part on which search operation has to be performed |
|
214 for all the messages under a particular folder entry |
|
215 @param aQueryIntValue: The corresponding value of the message part that needs to |
|
216 be searched |
|
217 @param aRelOp An enumeration corresponding to a relational operator used against a |
|
218 particular message part for all the messages in a particular folder during the |
|
219 search operation |
|
220 |
|
221 @return None |
|
222 @leave KErrNone - Query is added successfully to search-sort query |
|
223 |
|
224 KErrArgument - An invalid value is passed for a particular message part |
|
225 |
|
226 KErrMsvInvalidOperator - An invalid operation is being performed |
|
227 on a particular message part |
|
228 |
|
229 KErrMsvQueryMaxLimit - An addition of search-sort operation has lead to a condition |
|
230 where the query options have exceeded the maximum number of search-sort options |
|
231 supported by messaging framework. The maximum search options that can be added |
|
232 to a search-sort query is ‘five’ and the maximum sort option that can be can be |
|
233 added is ‘one’ |
|
234 */ |
|
235 EXPORT_C void CMsvSearchSortQuery::AddSearchOptionL (TMsvMessagePart aMsgPart, const TInt aQueryIntValue, TMsvRelationOp aRelOp) |
|
236 { |
|
237 //check whether it's reached maximum query limit |
|
238 if(iQueryCount >= KMaxLevelOfSearchAndSort) |
|
239 { |
|
240 User::Leave(KErrMsvQueryMaxLimit); |
|
241 } |
|
242 |
|
243 if((aMsgPart == EMsvPriority || aMsgPart == EMsvMtmTypeUID) && (aRelOp == EMsvEqual || aRelOp == EMsvNotEqual)) |
|
244 { |
|
245 iIsSearchQuery = ETrue; |
|
246 iQueryTable[iQueryCount].iQueryString.AppendNum(aQueryIntValue); |
|
247 iQueryTable[iQueryCount].iMessagePart = aMsgPart; |
|
248 iQueryTable[iQueryCount].iRelationOp = aRelOp; |
|
249 iQueryCount++; |
|
250 } |
|
251 else if((aMsgPart == EMsvSize) && (aRelOp == EMsvEqual || aRelOp == EMsvNotEqual || aRelOp == EMsvLessThan || aRelOp == EMsvGreaterThan || aRelOp == EMsvLessThanOrEqual || aRelOp == EMsvGreaterThanOrEqual)) |
|
252 { |
|
253 //validating size field. |
|
254 if(aQueryIntValue <= 0) |
|
255 { |
|
256 User::Leave(KErrArgument); |
|
257 } |
|
258 //fill size info into query table |
|
259 iIsSearchQuery = ETrue; |
|
260 iQueryTable[iQueryCount].iQueryString.AppendNum(aQueryIntValue); |
|
261 iQueryTable[iQueryCount].iMessagePart = aMsgPart; |
|
262 iQueryTable[iQueryCount].iRelationOp = aRelOp; |
|
263 iQueryCount++; |
|
264 } |
|
265 else if((aMsgPart == EMsvAttachment ) && (aRelOp == EMsvEqual || aRelOp == EMsvNotEqual)) |
|
266 { |
|
267 TInt attachmentValue = 0; |
|
268 if(aQueryIntValue == 0) //to search EMsvFile from CMsvAttachment |
|
269 { |
|
270 /* |
|
271 * Internally assigning value 2 for EMsvFile, 3 for EMsvLinkedFile and 4 for EMsvMessageEntry |
|
272 * because values 0 & 1 used to check whether EMsvAttachment present or not. |
|
273 */ |
|
274 //for File attachment |
|
275 attachmentValue = aQueryIntValue + 2; |
|
276 } |
|
277 else if(aQueryIntValue == 1) //to search EMsvLinkedFile from CMsvAttachment |
|
278 { |
|
279 //for Linked file attachment |
|
280 attachmentValue = aQueryIntValue + 2; |
|
281 } |
|
282 else if(aQueryIntValue == 2) //to search EMsvMessageEntry from CMsvAttachment |
|
283 { |
|
284 //for Message entry attachment |
|
285 attachmentValue = aQueryIntValue + 2; |
|
286 } |
|
287 else |
|
288 { |
|
289 User::Leave(KErrArgument); |
|
290 } |
|
291 //fill attachment info into query table |
|
292 iIsSearchQuery = ETrue; |
|
293 iQueryTable[iQueryCount].iQueryString.AppendNum(attachmentValue); |
|
294 iQueryTable[iQueryCount].iMessagePart = aMsgPart; |
|
295 iQueryTable[iQueryCount].iRelationOp = aRelOp; |
|
296 iQueryCount++; |
|
297 } |
|
298 else |
|
299 { |
|
300 User::Leave(KErrArgument); |
|
301 } |
|
302 } |
|
303 |
|
304 /** |
|
305 Adds the search options to the search-sort query. |
|
306 This function is suitable when the message part value to be searched is a flag |
|
307 or a message status. |
|
308 |
|
309 @param aMsgPart A message part on which search operation has to be performed |
|
310 for all the messages under a particular folder entry |
|
311 @param aMessagePartFlagStatus:A Boolean value indicating if the flag indicated |
|
312 by the message part is set or not |
|
313 @return None |
|
314 @leave KErrNone - Query is added successfully to search-sort query |
|
315 |
|
316 KErrArgument - An invalid value is passed for a particular message part |
|
317 |
|
318 KErrMsvInvalidOperator - An invalid operation is being performed |
|
319 on a particular message part |
|
320 |
|
321 KErrMsvQueryMaxLimit - An addition of search-sort operation has lead to a condition |
|
322 where the query options have exceeded the maximum number of search-sort options |
|
323 supported by messaging framework. The maximum search options that can be added |
|
324 to a search-sort query is ‘five’ and the maximum sort option that can be can be |
|
325 added is ‘one’ |
|
326 */ |
|
327 |
|
328 EXPORT_C void CMsvSearchSortQuery::AddSearchOptionL (TMsvMessagePart aMsgPart, TBool aMessagePartFlagStatus) |
|
329 { |
|
330 //check whether it's reached maximum query limit |
|
331 if(iQueryCount >= KMaxLevelOfSearchAndSort) |
|
332 { |
|
333 User::Leave(KErrMsvQueryMaxLimit); |
|
334 } |
|
335 |
|
336 if(aMsgPart == EMsvNew || aMsgPart == EMsvUnreadMessages || aMsgPart == EMsvAttachment) |
|
337 { |
|
338 iIsSearchQuery = ETrue; |
|
339 |
|
340 iQueryTable[iQueryCount].iQueryString.AppendNum(aMessagePartFlagStatus); |
|
341 iQueryTable[iQueryCount].iMessagePart = aMsgPart; |
|
342 if(aMessagePartFlagStatus) |
|
343 { |
|
344 iQueryTable[iQueryCount].iRelationOp = EMsvEqual; |
|
345 } |
|
346 else |
|
347 { |
|
348 iQueryTable[iQueryCount].iRelationOp = EMsvNotEqual; |
|
349 } |
|
350 iQueryCount++; |
|
351 } |
|
352 else |
|
353 { |
|
354 User::Leave(KErrArgument); |
|
355 } |
|
356 } |
|
357 |
|
358 /** |
|
359 Adds sort options to the search-sort query, to enable sorting in ascending or |
|
360 descending order based on the message part added to the query |
|
361 |
|
362 @param aMsgPart: A message part on which a sort operation is performed for all |
|
363 the messages under a particular folder entry |
|
364 @param aSortOder: The sorting order in ascending or descending |
|
365 |
|
366 @return None |
|
367 @leave KErrNone - Query is added successfully to search-sort query |
|
368 KErrNotSupported - for multilevel sort |
|
369 */ |
|
370 |
|
371 EXPORT_C void CMsvSearchSortQuery::AddSortOptionL (TMsvMessagePart aMsgPart, TMsvSortOrder aSortOder) |
|
372 { |
|
373 if(aMsgPart == EMsvBody || iCountMultilevelSort >= 1) |
|
374 { |
|
375 User::Leave(KErrNotSupported); |
|
376 } |
|
377 |
|
378 if(aMsgPart < EMsvAttachment || aMsgPart > EMsvBody) |
|
379 { |
|
380 User::Leave(KErrArgument); |
|
381 } |
|
382 |
|
383 if(iIsSearchQuery) |
|
384 { |
|
385 iExplicitSort = ETrue; |
|
386 } |
|
387 iSortOnMessagePart = aMsgPart; |
|
388 iSortOrder = aSortOder; |
|
389 iCountMultilevelSort++; |
|
390 } |
|
391 |
|
392 |
|
393 /** |
|
394 Validate the query option sent by AddSearchOptionL () |
|
395 @param aMsgPart Search needs to be on this TMessagePart |
|
396 @param aQueryString The text to be found. |
|
397 @param aRelOp TMsgRelationOp enum's needs to used along with TMessagePart to create the query string |
|
398 @return KErrNone or KErrArgument or KErrMsvInvalidOperator |
|
399 */ |
|
400 TInt CMsvSearchSortQuery::ValidateQueryString(TMsvMessagePart aMsgPart, const TDesC& aQueryString, TMsvRelationOp aRelOp) |
|
401 { |
|
402 // these messageparts should come with EMsvEqual relation operator |
|
403 if((ValidateMessagePartAgainstEMsvEqualOperator(aMsgPart)) && aRelOp == EMsvEqual) |
|
404 { |
|
405 return KErrNone; |
|
406 } |
|
407 else if((aMsgPart == EMsvDate || aMsgPart == EMsvSize) && (ValidateMessagePartAgainstRelationOp(aRelOp))) |
|
408 { |
|
409 if(aMsgPart == EMsvDate) |
|
410 { |
|
411 //validating date field |
|
412 //TTime(aQueryString); |
|
413 TTime time; |
|
414 TInt error = time.Set(aQueryString); |
|
415 return error; |
|
416 } |
|
417 else |
|
418 { |
|
419 //validating size field. |
|
420 TInt size; |
|
421 TLex iLex(aQueryString); |
|
422 iLex.Val(size); |
|
423 if(size <= 0) |
|
424 { |
|
425 return KErrArgument ; |
|
426 } |
|
427 return KErrNone; |
|
428 } |
|
429 } |
|
430 else |
|
431 { |
|
432 return KErrArgument; |
|
433 } |
|
434 } |
|
435 |
|
436 |
|
437 /** |
|
438 get the message part from Query structure. |
|
439 @return TBool ETrue or EFalse |
|
440 */ |
|
441 TMsvMessagePart CMsvSearchSortQuery::GetMessagePart(TInt aIndex) |
|
442 { |
|
443 return iQueryTable[aIndex].iMessagePart; |
|
444 } |
|
445 |
|
446 /** |
|
447 get the sort field from the Query. |
|
448 @return TBool ETrue or EFalse |
|
449 */ |
|
450 TMsvMessagePart CMsvSearchSortQuery::GetMessagePart() |
|
451 { |
|
452 return iSortOnMessagePart; |
|
453 } |
|
454 |
|
455 /** |
|
456 get the size of Query. |
|
457 @return TBool ETrue or EFalse |
|
458 */ |
|
459 TInt CMsvSearchSortQuery::GetMaxQuerySize() |
|
460 { |
|
461 return iQueryCount; |
|
462 } |
|
463 |
|
464 |
|
465 /** |
|
466 Get Relation operator |
|
467 @return TSearchSortResultType results as TMsvId or TMsvEntry |
|
468 */ |
|
469 TMsvRelationOp CMsvSearchSortQuery::GetRelationOp(TInt aIndex) |
|
470 { |
|
471 return iQueryTable[aIndex].iRelationOp; |
|
472 } |
|
473 |
|
474 /** |
|
475 Get search sort result type set by client. |
|
476 @return TSearchSortResultType results as TMsvId or TMsvEntry |
|
477 */ |
|
478 TMsvSearchSortResultType CMsvSearchSortQuery::GetResultType () |
|
479 { |
|
480 return iSearchSortResultType; |
|
481 } |
|
482 |
|
483 |
|
484 /** |
|
485 Function to check whether whole word search enabled or not. |
|
486 @return ETrue or EFalse |
|
487 */ |
|
488 TBool CMsvSearchSortQuery::IsWholeWord() |
|
489 { |
|
490 return iWholeWord; |
|
491 } |
|
492 |
|
493 /** |
|
494 Function to check whether case sensitivesearch search enabled. |
|
495 @return ETrue or EFalse |
|
496 */ |
|
497 TBool CMsvSearchSortQuery::IsCaseSensitive() |
|
498 { |
|
499 return iCaseSensitive; |
|
500 } |
|
501 |
|
502 /** |
|
503 Function to check whether wildcard character search enabled. |
|
504 @return ETrue or EFalse |
|
505 */ |
|
506 TBool CMsvSearchSortQuery::IsWildCardSearch() |
|
507 { |
|
508 return iWildCardCharacter; |
|
509 } |
|
510 |
|
511 /** |
|
512 Function to check whether sub folder search enabled. |
|
513 @return ETrue or EFalse |
|
514 */ |
|
515 TBool CMsvSearchSortQuery::IsSubFolderSearch() |
|
516 { |
|
517 return iSubFolderSearch; |
|
518 } |
|
519 |
|
520 /** |
|
521 Function to validate, is this search Query. |
|
522 @return TBool ETrue or EFalse |
|
523 */ |
|
524 TBool CMsvSearchSortQuery::IsSearchQuery() |
|
525 { |
|
526 return iIsSearchQuery; |
|
527 } |
|
528 |
|
529 //Validate TMsvMessagePart with EMsvEqual Operator |
|
530 TBool CMsvSearchSortQuery::ValidateMessagePartAgainstEMsvEqualOperator(TMsvMessagePart aMessagePart) |
|
531 { |
|
532 TBool validate = EFalse; |
|
533 switch(aMessagePart) |
|
534 { |
|
535 case EMsvSubject: |
|
536 case EMsvDetails: |
|
537 case EMsvDescription: |
|
538 case EMsvTo: |
|
539 case EMsvFrom: |
|
540 case EMsvCc: |
|
541 case EMsvBcc: |
|
542 case EMsvBody: |
|
543 validate = ETrue; |
|
544 break; |
|
545 |
|
546 default: |
|
547 validate = EFalse; |
|
548 } |
|
549 |
|
550 return validate; |
|
551 } |
|
552 |
|
553 //Validate TMsvMessagePart against TMsvRelationOp Operator |
|
554 TBool CMsvSearchSortQuery::ValidateMessagePartAgainstRelationOp(TMsvRelationOp aRelationOp) |
|
555 { |
|
556 TBool validate = EFalse; |
|
557 switch(aRelationOp) |
|
558 { |
|
559 case EMsvEqual: |
|
560 case EMsvNotEqual: |
|
561 case EMsvLessThan: |
|
562 case EMsvLessThanOrEqual: |
|
563 case EMsvGreaterThan: |
|
564 case EMsvGreaterThanOrEqual: |
|
565 validate = ETrue; |
|
566 break; |
|
567 |
|
568 default: |
|
569 validate = EFalse; |
|
570 } |
|
571 |
|
572 return validate; |
|
573 } |