|
1 /* |
|
2 * Copyright (c) 2002-2005 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 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 |
|
22 #include <SyncMLTransportProperties.h> |
|
23 |
|
24 |
|
25 #include "aspfilter.h" |
|
26 #include "aspprofile.h" |
|
27 #include "AspResHandler.h" |
|
28 #include "AspDialogUtil.h" |
|
29 |
|
30 |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 |
|
35 |
|
36 /******************************************************************************* |
|
37 * class CAspFilterList |
|
38 *******************************************************************************/ |
|
39 |
|
40 |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CAspFilterList::NewL |
|
44 // |
|
45 // Two-phased constructor. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CAspFilterList* CAspFilterList::NewL(const TAspParam& aParam, RPointerArray<CSyncMLFilter>& aArray) |
|
49 { |
|
50 CAspFilterList* self = new(ELeave) CAspFilterList(aParam, aArray); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop(self); |
|
54 |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CAspFilterList::~CAspFilterList |
|
61 // |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CAspFilterList::~CAspFilterList() |
|
65 { |
|
66 iFilterList.ResetAndDestroy(); |
|
67 iFilterList.Close(); |
|
68 } |
|
69 |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CAspFilterList::ConstructL |
|
73 // |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CAspFilterList::ConstructL() |
|
77 { |
|
78 InitFiltersL(); |
|
79 } |
|
80 |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CAspFilterList::CAspFilterList |
|
84 // |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CAspFilterList::CAspFilterList(const TAspParam& aParam, RPointerArray<CSyncMLFilter>& aArray) |
|
88 { |
|
89 iApplicationId = aParam.iApplicationId; |
|
90 //iAspTask = aParam.iSyncTask; |
|
91 iArray = aArray; |
|
92 } |
|
93 |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CAspFilterList::InitFiltersL |
|
97 // |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void CAspFilterList::InitFiltersL() |
|
101 { |
|
102 //TSyncMLFilterChangeInfo changeInfo = ESyncMLDefault; |
|
103 //RPointerArray<CSyncMLFilter>& arr = iAspTask->Task().SupportedServerFiltersL(changeInfo); |
|
104 |
|
105 TInt count = iArray.Count(); |
|
106 for (TInt i=0; i<count; i++) |
|
107 { |
|
108 CSyncMLFilter* filter = iArray[i]; |
|
109 CAspFilter* aspFilter = CAspFilter::NewLC(filter, i); |
|
110 iFilterList.AppendL(aspFilter); |
|
111 CleanupStack::Pop(aspFilter); |
|
112 } |
|
113 } |
|
114 |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CAspFilterList::Count |
|
118 // |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 TInt CAspFilterList::Count() |
|
122 { |
|
123 return iFilterList.Count(); |
|
124 } |
|
125 |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CAspFilterList::FiltersEnabled |
|
129 // |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TBool CAspFilterList::FiltersEnabled() |
|
133 { |
|
134 TInt count = iFilterList.Count(); |
|
135 |
|
136 for (TInt i=0; i<count; i++) |
|
137 { |
|
138 CAspFilter* filter = iFilterList[i]; |
|
139 if (filter->Enabled()) |
|
140 { |
|
141 return ETrue; |
|
142 } |
|
143 } |
|
144 |
|
145 return EFalse; |
|
146 } |
|
147 |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CAspFilterList::SetFiltersEnabledL |
|
151 // |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CAspFilterList::SetFiltersEnabledL(TBool aEnable) |
|
155 { |
|
156 TInt count = iFilterList.Count(); |
|
157 |
|
158 for (TInt i=0; i<count; i++) |
|
159 { |
|
160 CAspFilter* filter = iFilterList[i]; |
|
161 filter->SetEnabledL(aEnable); |
|
162 } |
|
163 } |
|
164 |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CAspFilterList::SaveL |
|
168 // |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 void CAspFilterList::SaveL() |
|
172 { |
|
173 } |
|
174 |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CAspFilterList::Item |
|
178 // |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 CAspFilter* CAspFilterList::Item(TInt aIndex) |
|
182 { |
|
183 if (aIndex < 0 || aIndex >= iFilterList.Count()) |
|
184 { |
|
185 TUtil::Panic(KErrArgument); |
|
186 } |
|
187 |
|
188 return iFilterList[aIndex]; |
|
189 } |
|
190 |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CAspFilterList::ItemForIdL |
|
194 // |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 CAspFilter* CAspFilterList::ItemForId(TInt aId) |
|
198 { |
|
199 TInt count = iFilterList.Count(); |
|
200 |
|
201 for (TInt i=0; i<count; i++) |
|
202 { |
|
203 CAspFilter* filter = iFilterList[i]; |
|
204 if (filter->Id() == aId) |
|
205 { |
|
206 return filter; |
|
207 } |
|
208 } |
|
209 |
|
210 return NULL; |
|
211 } |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 /******************************************************************************* |
|
218 * class CAspFilter |
|
219 *******************************************************************************/ |
|
220 |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CAspFilter::NewLC |
|
224 // |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 CAspFilter* CAspFilter::NewLC(CSyncMLFilter* aSyncFilter, TInt aId) |
|
228 { |
|
229 CAspFilter* self = new(ELeave) CAspFilter(aSyncFilter, aId); |
|
230 CleanupStack::PushL(self); |
|
231 self->ConstructL(); |
|
232 |
|
233 return self; |
|
234 } |
|
235 |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CAspFilter::~CAspFilter |
|
239 // |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 CAspFilter::~CAspFilter() |
|
243 { |
|
244 iFilterItemList.ResetAndDestroy(); |
|
245 iFilterItemList.Close(); |
|
246 } |
|
247 |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CAspFilter::ConstructL |
|
251 // |
|
252 // Symbian 2nd phase constructor can leave. |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CAspFilter::ConstructL() |
|
256 { |
|
257 InitFilterItemsL(); |
|
258 } |
|
259 |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CAspFilter::CAspFilter |
|
263 // |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 CAspFilter::CAspFilter(CSyncMLFilter* aSyncFilter, TInt aId) |
|
267 { |
|
268 iId = KFilterBaseId + aId; |
|
269 iSyncFilter = aSyncFilter; |
|
270 |
|
271 __ASSERT_ALWAYS(iSyncFilter, TUtil::Panic(KErrGeneral)); |
|
272 } |
|
273 |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CAspFilter::SaveL |
|
277 // |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 void CAspFilter::SaveL() |
|
281 { |
|
282 } |
|
283 |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CAspFilter::InitFilterItemsL |
|
287 // |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void CAspFilter::InitFilterItemsL() |
|
291 { |
|
292 RPointerArray<CSyncMLFilterProperty>& arr = iSyncFilter->FilterProperties(); |
|
293 |
|
294 TInt count = arr.Count(); |
|
295 for (TInt i=0; i<count; i++) |
|
296 { |
|
297 CSyncMLFilterProperty* property = arr[i]; |
|
298 CAspFilterItem* item = CAspFilterItem::NewLC(property, i); |
|
299 iFilterItemList.AppendL(item); |
|
300 CleanupStack::Pop(item); |
|
301 } |
|
302 } |
|
303 |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CAspFilter::DisplayName |
|
307 // |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 const TDesC& CAspFilter::DisplayName() |
|
311 { |
|
312 return iSyncFilter->DisplayName(); |
|
313 } |
|
314 |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CAspFilter::GetDisplayValueL |
|
318 // |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 void CAspFilter::GetDisplayValueL(TDes& aText) |
|
322 { |
|
323 aText = KNullDesC; |
|
324 |
|
325 if (!Enabled()) |
|
326 { |
|
327 CAspResHandler::ReadL(aText, R_ASP_NOT_DEFINED); |
|
328 } |
|
329 else if (iFilterItemList.Count() == 1) |
|
330 { |
|
331 CAspFilterItem* item = iFilterItemList[0]; |
|
332 item->GetDisplayValueL(aText); |
|
333 } |
|
334 else if (iFilterItemList.Count() > 1) |
|
335 { |
|
336 CAspResHandler::ReadL(aText, R_ASP_MULTIPLE_SELECTION); |
|
337 } |
|
338 } |
|
339 |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // CAspFilter::Id |
|
343 // |
|
344 // ----------------------------------------------------------------------------- |
|
345 // |
|
346 TInt CAspFilter::Id() |
|
347 { |
|
348 return iId; |
|
349 } |
|
350 |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CAspFilter::ItemCount |
|
354 // |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 TInt CAspFilter::ItemCount() |
|
358 { |
|
359 return iFilterItemList.Count(); |
|
360 } |
|
361 |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // CAspFilter::Item |
|
365 // |
|
366 // ----------------------------------------------------------------------------- |
|
367 // |
|
368 CAspFilterItem* CAspFilter::Item(TInt aIndex) |
|
369 { |
|
370 if (aIndex < 0 || aIndex >= ItemCount()) |
|
371 { |
|
372 TUtil::Panic(KErrArgument); |
|
373 } |
|
374 |
|
375 return iFilterItemList[aIndex]; |
|
376 } |
|
377 |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // CAspFilter::ItemForIdL |
|
381 // |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 CAspFilterItem* CAspFilter::ItemForId(TInt aId) |
|
385 { |
|
386 TInt count = ItemCount(); |
|
387 |
|
388 for (TInt i=0; i<count; i++) |
|
389 { |
|
390 CAspFilterItem* item = Item(i); |
|
391 if (item->Id() == aId) |
|
392 { |
|
393 return item; |
|
394 } |
|
395 } |
|
396 |
|
397 return NULL; |
|
398 } |
|
399 |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // CAspFilter::Enabled |
|
403 // |
|
404 // ----------------------------------------------------------------------------- |
|
405 // |
|
406 TBool CAspFilter::Enabled() |
|
407 { |
|
408 return iSyncFilter->Enabled(); |
|
409 } |
|
410 |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 // CAspFilter::SetEnabledL |
|
414 // |
|
415 // ----------------------------------------------------------------------------- |
|
416 // |
|
417 void CAspFilter::SetEnabledL(TBool aEnable) |
|
418 { |
|
419 iSyncFilter->SetEnabledL(aEnable); |
|
420 } |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 /******************************************************************************* |
|
429 * class CAspFilterItem |
|
430 *******************************************************************************/ |
|
431 |
|
432 |
|
433 // ----------------------------------------------------------------------------- |
|
434 // CAspFilterItem::NewLC |
|
435 // |
|
436 // ----------------------------------------------------------------------------- |
|
437 // |
|
438 CAspFilterItem* CAspFilterItem::NewLC(CSyncMLFilterProperty* aProperty, TInt aId) |
|
439 { |
|
440 CAspFilterItem* self = new(ELeave) CAspFilterItem(aProperty, aId); |
|
441 CleanupStack::PushL(self); |
|
442 self->ConstructL(); |
|
443 |
|
444 return self; |
|
445 } |
|
446 |
|
447 |
|
448 // ----------------------------------------------------------------------------- |
|
449 // CAspFilterItem::NewL |
|
450 // |
|
451 // ----------------------------------------------------------------------------- |
|
452 // |
|
453 CAspFilterItem* CAspFilterItem::NewL(CSyncMLFilterProperty* aProperty, TInt aId) |
|
454 { |
|
455 CAspFilterItem* self = new(ELeave) CAspFilterItem(aProperty, aId); |
|
456 CleanupStack::PushL(self); |
|
457 self->ConstructL(); |
|
458 CleanupStack::Pop(self); |
|
459 |
|
460 return self; |
|
461 } |
|
462 |
|
463 |
|
464 // ----------------------------------------------------------------------------- |
|
465 // CAspFilterItem::~CAspFilterItem |
|
466 // |
|
467 // ----------------------------------------------------------------------------- |
|
468 // |
|
469 CAspFilterItem::~CAspFilterItem() |
|
470 { |
|
471 } |
|
472 |
|
473 |
|
474 // ----------------------------------------------------------------------------- |
|
475 // CAspFilterItem::ConstructL |
|
476 // |
|
477 // ----------------------------------------------------------------------------- |
|
478 // |
|
479 void CAspFilterItem::ConstructL() |
|
480 { |
|
481 InitListTypeL(); |
|
482 InitDataTypeL(); |
|
483 } |
|
484 |
|
485 |
|
486 // ----------------------------------------------------------------------------- |
|
487 // CAspFilterItem::CAspFilterItem |
|
488 // ----------------------------------------------------------------------------- |
|
489 // |
|
490 CAspFilterItem::CAspFilterItem(CSyncMLFilterProperty* aProperty, TInt aId) |
|
491 { |
|
492 iId = aId + KFilterItemBaseId; |
|
493 iProperty = aProperty; |
|
494 |
|
495 __ASSERT_ALWAYS(iProperty, TUtil::Panic(KErrGeneral)); |
|
496 } |
|
497 |
|
498 |
|
499 // ----------------------------------------------------------------------------- |
|
500 // CAspFilterItem::ListType |
|
501 // |
|
502 // ----------------------------------------------------------------------------- |
|
503 // |
|
504 TInt CAspFilterItem::ListType() |
|
505 { |
|
506 return iListType; |
|
507 } |
|
508 |
|
509 |
|
510 // ----------------------------------------------------------------------------- |
|
511 // CAspFilterItem::DataType |
|
512 // |
|
513 // ----------------------------------------------------------------------------- |
|
514 // |
|
515 TInt CAspFilterItem::DataType() |
|
516 { |
|
517 return iDataType; |
|
518 } |
|
519 |
|
520 |
|
521 // ----------------------------------------------------------------------------- |
|
522 // CAspFilterItem::InitListType |
|
523 // |
|
524 // ----------------------------------------------------------------------------- |
|
525 // |
|
526 void CAspFilterItem::InitListTypeL() |
|
527 { |
|
528 TInt defaultValueCount = iProperty->DefaultValueCount(); |
|
529 TBool querySupported = iProperty->CanUseQueryValue(); |
|
530 TBool multiSelectionSupported = iProperty->SupportsMultipleSelection(); |
|
531 |
|
532 if (defaultValueCount == 0 && querySupported) |
|
533 { |
|
534 iListType = ETypeQuery; |
|
535 } |
|
536 else if (defaultValueCount > 0 && !querySupported && !multiSelectionSupported) |
|
537 { |
|
538 iListType = ETypeSingleSelection; |
|
539 } |
|
540 else if (defaultValueCount > 0 && querySupported && !multiSelectionSupported) |
|
541 { |
|
542 iListType = ETypeSingleSelectionUserDefined; |
|
543 } |
|
544 else if (defaultValueCount > 0 && !querySupported && multiSelectionSupported) |
|
545 { |
|
546 iListType = ETypeMultipleSelection; |
|
547 } |
|
548 else if (defaultValueCount > 0 && querySupported && multiSelectionSupported) |
|
549 { |
|
550 iListType = ETypeMultipleSelectionUserDefined; |
|
551 } |
|
552 else |
|
553 { |
|
554 User::Leave(KErrNotSupported); |
|
555 } |
|
556 } |
|
557 |
|
558 |
|
559 // ----------------------------------------------------------------------------- |
|
560 // CAspFilterItem::InitDataType |
|
561 // |
|
562 // ----------------------------------------------------------------------------- |
|
563 // |
|
564 void CAspFilterItem::InitDataTypeL() |
|
565 { |
|
566 if (!iProperty->CanUseQueryValue()) |
|
567 { |
|
568 iDataType = CAspListItemData::ETypeList; |
|
569 return; |
|
570 } |
|
571 |
|
572 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
573 |
|
574 switch (type) |
|
575 { |
|
576 case ESyncMLDataTypeBool: |
|
577 iDataType = CAspListItemData::ETypeBoolean; |
|
578 break; |
|
579 case ESyncMLDataTypeNumber: |
|
580 iDataType = CAspListItemData::ETypeNumber; |
|
581 break; |
|
582 case ESyncMLDataTypeDate: |
|
583 iDataType = CAspListItemData::ETypeDate; |
|
584 break; |
|
585 case ESyncMLDataTypeTime: |
|
586 iDataType = CAspListItemData::ETypeTime; |
|
587 break; |
|
588 case ESyncMLDataTypeText8: |
|
589 iDataType = CAspListItemData::ETypeText; |
|
590 break; |
|
591 case ESyncMLDataTypeText16: |
|
592 iDataType = CAspListItemData::ETypeText; |
|
593 break; |
|
594 |
|
595 default: |
|
596 User::Leave(KErrNotSupported); |
|
597 break; |
|
598 } |
|
599 } |
|
600 |
|
601 |
|
602 // ----------------------------------------------------------------------------- |
|
603 // CAspFilterItem::DisplayName |
|
604 // |
|
605 // ----------------------------------------------------------------------------- |
|
606 // |
|
607 const TDesC& CAspFilterItem::DisplayName() |
|
608 { |
|
609 return iProperty->DisplayName(); |
|
610 } |
|
611 |
|
612 |
|
613 // ----------------------------------------------------------------------------- |
|
614 // CAspFilterItem::DisplayValueL |
|
615 // |
|
616 // ----------------------------------------------------------------------------- |
|
617 // |
|
618 const TDesC& CAspFilterItem::DisplayValueL() |
|
619 { |
|
620 GetDisplayValueL(iDisplayValueBuf); |
|
621 return iDisplayValueBuf; |
|
622 } |
|
623 |
|
624 |
|
625 // ----------------------------------------------------------------------------- |
|
626 // CAspFilterItem::GetDisplayValueL |
|
627 // |
|
628 // ----------------------------------------------------------------------------- |
|
629 // |
|
630 void CAspFilterItem::GetDisplayValueL(TDes& aText) |
|
631 { |
|
632 aText = KNullDesC; |
|
633 |
|
634 if (ListType() == ETypeQuery) |
|
635 { |
|
636 GetQueryValueTextL(aText); |
|
637 } |
|
638 else if (SelectionAndQueryCount() > 1) |
|
639 { |
|
640 CAspResHandler::ReadL(aText, R_ASP_MULTIPLE_SELECTION); |
|
641 } |
|
642 else if (SelectionAndQueryCount() == 1) |
|
643 { |
|
644 if (QueryValueSelected()) |
|
645 { |
|
646 GetQueryValueTextL(aText); |
|
647 } |
|
648 else |
|
649 { |
|
650 GetListValueTextL(aText); |
|
651 } |
|
652 } |
|
653 } |
|
654 |
|
655 |
|
656 // ----------------------------------------------------------------------------- |
|
657 // CAspFilterItem::GetQueryValueTextL |
|
658 // |
|
659 // ----------------------------------------------------------------------------- |
|
660 // |
|
661 void CAspFilterItem::GetQueryValueTextL(TDes& aText) |
|
662 { |
|
663 aText = KNullDesC; |
|
664 |
|
665 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
666 |
|
667 switch (type) |
|
668 { |
|
669 case ESyncMLDataTypeText16: |
|
670 GetText(aText); |
|
671 break; |
|
672 |
|
673 case ESyncMLDataTypeText8: |
|
674 GetText(aText); |
|
675 break; |
|
676 |
|
677 case ESyncMLDataTypeNumber: |
|
678 aText.Num(iProperty->QueryValueIntL()); |
|
679 break; |
|
680 |
|
681 case ESyncMLDataTypeBool: |
|
682 { |
|
683 CDesCArray* stringData = CAspResHandler::ReadDesArrayStaticLC(R_ASP_FILTER_ITEM_YESNO); |
|
684 if (iProperty->QueryValueBoolL()) |
|
685 { |
|
686 aText = (*stringData)[1]; |
|
687 } |
|
688 else |
|
689 { |
|
690 aText = (*stringData)[0]; |
|
691 } |
|
692 CleanupStack::PopAndDestroy(stringData); |
|
693 break; |
|
694 } |
|
695 |
|
696 case ESyncMLDataTypeDate: |
|
697 TUtil::GetDateTextL(aText, iProperty->QueryValueDateL()); |
|
698 break; |
|
699 |
|
700 case ESyncMLDataTypeTime: |
|
701 TUtil::GetTimeTextL(aText, iProperty->QueryValueTimeL()); |
|
702 break; |
|
703 |
|
704 default: |
|
705 break; |
|
706 |
|
707 } |
|
708 |
|
709 |
|
710 if (TUtil::IsEmpty(aText)) |
|
711 { |
|
712 CAspResHandler::ReadL(aText, R_ASP_SETTING_VALUE_NONE); |
|
713 } |
|
714 } |
|
715 |
|
716 |
|
717 // ----------------------------------------------------------------------------- |
|
718 // CAspFilterItem::SetQueryValueTextL |
|
719 // |
|
720 // ----------------------------------------------------------------------------- |
|
721 // |
|
722 void CAspFilterItem::SetQueryValueTextL(const TDesC& aText) |
|
723 { |
|
724 TInt num = 0; |
|
725 |
|
726 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
727 |
|
728 switch (type) |
|
729 { |
|
730 case ESyncMLDataTypeText16: |
|
731 iProperty->SetQueryValueText16L(aText); |
|
732 break; |
|
733 |
|
734 case ESyncMLDataTypeText8: |
|
735 TUtil::StrCopy(iBuf8, aText); |
|
736 iProperty->SetQueryValueText8L(iBuf8); |
|
737 break; |
|
738 |
|
739 case ESyncMLDataTypeNumber: |
|
740 User::LeaveIfError(TUtil::StrToInt(aText, num)); |
|
741 iProperty->SetQueryValueIntL(num); |
|
742 break; |
|
743 |
|
744 case ESyncMLDataTypeBool: |
|
745 User::LeaveIfError(TUtil::StrToInt(aText, num)); |
|
746 if (num) |
|
747 { |
|
748 iProperty->SetQueryValueBoolL(ETrue); |
|
749 } |
|
750 else |
|
751 { |
|
752 iProperty->SetQueryValueBoolL(EFalse); |
|
753 } |
|
754 break; |
|
755 |
|
756 case ESyncMLDataTypeDate: |
|
757 User::LeaveIfError(TUtil::StrToInt(aText, num)); |
|
758 iProperty->SetQueryValueDateL(num); |
|
759 break; |
|
760 |
|
761 case ESyncMLDataTypeTime: |
|
762 User::LeaveIfError(TUtil::StrToInt(aText, num)); |
|
763 iProperty->SetQueryValueTimeL(num); |
|
764 break; |
|
765 |
|
766 default: |
|
767 break; |
|
768 |
|
769 } |
|
770 } |
|
771 |
|
772 |
|
773 // ----------------------------------------------------------------------------- |
|
774 // CAspFilterItem::GetListValueTextL |
|
775 // |
|
776 // ----------------------------------------------------------------------------- |
|
777 // |
|
778 void CAspFilterItem::GetListValueTextL(TDes& aText) |
|
779 { |
|
780 aText = KNullDesC; |
|
781 TInt index = SelectionIndex(); |
|
782 if (index == KErrNotFound) |
|
783 { |
|
784 CAspResHandler::ReadL(aText, R_ASP_SETTING_VALUE_NONE); |
|
785 return; // list does not have one item selected |
|
786 } |
|
787 |
|
788 GetListValueTextL(aText, index); |
|
789 } |
|
790 |
|
791 |
|
792 // ----------------------------------------------------------------------------- |
|
793 // CAspFilterItem::GetListValueTextL |
|
794 // |
|
795 // ----------------------------------------------------------------------------- |
|
796 // |
|
797 void CAspFilterItem::GetListValueTextL(TDes& aText, TInt aIndex) |
|
798 { |
|
799 aText = KNullDesC; |
|
800 |
|
801 if (aIndex < 0 || aIndex >= iProperty->DefaultValueCount()) |
|
802 { |
|
803 TUtil::Panic(KErrArgument); |
|
804 } |
|
805 |
|
806 TSyncMLFilterPropertyDataType type = iProperty->DefaultValueDataType(); |
|
807 |
|
808 switch (type) |
|
809 { |
|
810 case ESyncMLDataTypeText16: |
|
811 TUtil::StrCopy(aText, iProperty->DefaultValueText16L(aIndex)); |
|
812 break; |
|
813 |
|
814 case ESyncMLDataTypeText8: |
|
815 TUtil::StrCopy(aText, iProperty->DefaultValueText8L(aIndex)); |
|
816 break; |
|
817 |
|
818 case ESyncMLDataTypeNumber: |
|
819 aText.Num(iProperty->DefaultValueIntL(aIndex)); |
|
820 break; |
|
821 |
|
822 case ESyncMLDataTypeBool: |
|
823 { |
|
824 CDesCArray* stringData = CAspResHandler::ReadDesArrayStaticLC(R_ASP_FILTER_ITEM_YESNO); |
|
825 if (iProperty->DefaultValueBoolL(aIndex)) |
|
826 { |
|
827 aText = (*stringData)[1]; |
|
828 } |
|
829 else |
|
830 { |
|
831 aText = (*stringData)[0]; |
|
832 } |
|
833 CleanupStack::PopAndDestroy(stringData); |
|
834 break; |
|
835 } |
|
836 |
|
837 case ESyncMLDataTypeDate: |
|
838 TUtil::GetDateTextL(aText, iProperty->DefaultValueDateL(aIndex)); |
|
839 break; |
|
840 |
|
841 case ESyncMLDataTypeTime: |
|
842 TUtil::GetTimeTextL(aText, iProperty->DefaultValueTimeL(aIndex)); |
|
843 break; |
|
844 |
|
845 default: |
|
846 break; |
|
847 |
|
848 } |
|
849 } |
|
850 |
|
851 |
|
852 // ----------------------------------------------------------------------------- |
|
853 // CAspFilterItem::SelectionCount |
|
854 // |
|
855 // ----------------------------------------------------------------------------- |
|
856 // |
|
857 TInt CAspFilterItem::SelectionCount() |
|
858 { |
|
859 TInt count = 0; |
|
860 TInt defaultValueCount = iProperty->DefaultValueCount(); |
|
861 |
|
862 for (TInt i=0; i<defaultValueCount; i++) |
|
863 { |
|
864 if (iProperty->IsDefaultValueSelected(i)) |
|
865 { |
|
866 count++; |
|
867 } |
|
868 } |
|
869 |
|
870 return count; |
|
871 } |
|
872 |
|
873 |
|
874 // ----------------------------------------------------------------------------- |
|
875 // CAspFilterItem::SelectionAndQueryCount |
|
876 // |
|
877 // ----------------------------------------------------------------------------- |
|
878 // |
|
879 TInt CAspFilterItem::SelectionAndQueryCount() |
|
880 { |
|
881 TInt count = SelectionCount(); |
|
882 |
|
883 if (QueryValueSelected()) |
|
884 { |
|
885 count++; |
|
886 } |
|
887 |
|
888 return count; |
|
889 } |
|
890 |
|
891 |
|
892 // ----------------------------------------------------------------------------- |
|
893 // CAspFilterItem::SelectionIndex |
|
894 // |
|
895 // ----------------------------------------------------------------------------- |
|
896 // |
|
897 TInt CAspFilterItem::SelectionIndex() |
|
898 { |
|
899 if (SelectionCount() != 1) |
|
900 { |
|
901 return KErrNotFound; |
|
902 } |
|
903 if (QueryValueSelected()) |
|
904 { |
|
905 return KErrNotFound; |
|
906 } |
|
907 |
|
908 TInt count = iProperty->DefaultValueCount(); |
|
909 |
|
910 for (TInt i=0; i<count; i++) |
|
911 { |
|
912 if (iProperty->IsDefaultValueSelected(i)) |
|
913 { |
|
914 return i; |
|
915 } |
|
916 } |
|
917 |
|
918 return KErrNotFound; |
|
919 } |
|
920 |
|
921 |
|
922 // ----------------------------------------------------------------------------- |
|
923 // CAspFilterItem::QueryValueSelected |
|
924 // |
|
925 // ----------------------------------------------------------------------------- |
|
926 // |
|
927 TBool CAspFilterItem::QueryValueSelected() |
|
928 { |
|
929 if (iProperty->DefaultValueCount() > 0 && iProperty->CanUseQueryValue()) |
|
930 { |
|
931 if (iProperty->IsQueryValueSelected()) |
|
932 { |
|
933 return ETrue; |
|
934 } |
|
935 } |
|
936 |
|
937 return EFalse; |
|
938 } |
|
939 |
|
940 |
|
941 // ----------------------------------------------------------------------------- |
|
942 // CAspFilterItem::Id |
|
943 // |
|
944 // ----------------------------------------------------------------------------- |
|
945 // |
|
946 TInt CAspFilterItem::Id() |
|
947 { |
|
948 return iId; |
|
949 } |
|
950 |
|
951 |
|
952 // ----------------------------------------------------------------------------- |
|
953 // CAspFilterItem::IsMandatory |
|
954 // |
|
955 // ----------------------------------------------------------------------------- |
|
956 // |
|
957 TBool CAspFilterItem::IsMandatory() |
|
958 { |
|
959 if (iListType == ETypeMultipleSelection || iListType == ETypeMultipleSelectionUserDefined) |
|
960 { |
|
961 if (!iProperty->SupportsEmptySelection()) |
|
962 { |
|
963 return ETrue; |
|
964 } |
|
965 } |
|
966 |
|
967 return EFalse; |
|
968 } |
|
969 |
|
970 |
|
971 // ----------------------------------------------------------------------------- |
|
972 // CAspFilterItem::MaxLength |
|
973 // |
|
974 // ----------------------------------------------------------------------------- |
|
975 // |
|
976 TInt CAspFilterItem::MaxLength() |
|
977 { |
|
978 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
979 if (type != ESyncMLDataTypeText8 && type != ESyncMLDataTypeText16) |
|
980 { |
|
981 return 0; |
|
982 } |
|
983 |
|
984 return iProperty->MaxTextLength(); |
|
985 } |
|
986 |
|
987 |
|
988 // ----------------------------------------------------------------------------- |
|
989 // CAspFilterItem::GetSelectionL |
|
990 // |
|
991 // ----------------------------------------------------------------------------- |
|
992 // |
|
993 void CAspFilterItem::GetSelectionL(CSelectionItemList* aList) |
|
994 { |
|
995 __ASSERT_ALWAYS(aList, TUtil::Panic(KErrGeneral)); |
|
996 |
|
997 TBuf<KBufSize> buf; |
|
998 |
|
999 TInt count = iProperty->DefaultValueCount(); |
|
1000 for (TInt i=0; i<count; i++) |
|
1001 { |
|
1002 TBool selected = iProperty->IsDefaultValueSelected(i); |
|
1003 GetListValueTextL(buf, i); |
|
1004 |
|
1005 CSelectableItem* item = new (ELeave) CSelectableItem(buf, selected); |
|
1006 CleanupStack::PushL(item); |
|
1007 item->ConstructL(); |
|
1008 aList->AppendL(item); |
|
1009 CleanupStack::Pop(item); |
|
1010 } |
|
1011 |
|
1012 AddQueryValueL(aList); |
|
1013 } |
|
1014 |
|
1015 |
|
1016 // ----------------------------------------------------------------------------- |
|
1017 // CAspFilterItem::SetSelectionL |
|
1018 // |
|
1019 // ----------------------------------------------------------------------------- |
|
1020 // |
|
1021 void CAspFilterItem::SetSelectionL(CSelectionItemList* aList) |
|
1022 { |
|
1023 TInt count = aList->Count(); |
|
1024 TInt defaultValuecount = iProperty->DefaultValueCount(); |
|
1025 |
|
1026 __ASSERT_ALWAYS(count >= defaultValuecount, TUtil::Panic(KErrGeneral)); |
|
1027 |
|
1028 for (TInt i=0; i<defaultValuecount; i++) |
|
1029 { |
|
1030 TBool selected = (*aList)[i]->SelectionStatus(); |
|
1031 if (selected) |
|
1032 { |
|
1033 iProperty->SelectDefaultValueL(i); |
|
1034 } |
|
1035 else |
|
1036 { |
|
1037 iProperty->UnselectDefaultValueL(i); |
|
1038 } |
|
1039 } |
|
1040 |
|
1041 UpdateQueryValueL(aList); |
|
1042 |
|
1043 CheckEmptySelectionL(); |
|
1044 } |
|
1045 |
|
1046 |
|
1047 // ----------------------------------------------------------------------------- |
|
1048 // CAspFilterItem::CheckEmptySelectionL |
|
1049 // |
|
1050 // ----------------------------------------------------------------------------- |
|
1051 // |
|
1052 void CAspFilterItem::CheckEmptySelectionL() |
|
1053 { |
|
1054 if (iListType != ETypeMultipleSelection && iListType != ETypeMultipleSelectionUserDefined) |
|
1055 { |
|
1056 return; |
|
1057 } |
|
1058 |
|
1059 if (SelectionAndQueryCount() == 0 && !iProperty->SupportsEmptySelection()) |
|
1060 { |
|
1061 if (iProperty->DefaultValueCount() > 0) |
|
1062 { |
|
1063 iProperty->SelectDefaultValueL(0); |
|
1064 } |
|
1065 } |
|
1066 } |
|
1067 |
|
1068 |
|
1069 // ----------------------------------------------------------------------------- |
|
1070 // CAspFilterItem::UpdateQueryValueL |
|
1071 // |
|
1072 // ----------------------------------------------------------------------------- |
|
1073 // |
|
1074 void CAspFilterItem::UpdateQueryValueL(CSelectionItemList* aList) |
|
1075 { |
|
1076 if (iListType != ETypeSingleSelectionUserDefined && iListType != ETypeMultipleSelectionUserDefined) |
|
1077 { |
|
1078 return; |
|
1079 } |
|
1080 |
|
1081 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1082 if (type != ESyncMLDataTypeNumber && type != ESyncMLDataTypeText16 && type != ESyncMLDataTypeText8) |
|
1083 { |
|
1084 return; // "User defined" list only supports number and text |
|
1085 } |
|
1086 |
|
1087 |
|
1088 TInt count = aList->Count(); |
|
1089 TInt defaultValueCount = iProperty->DefaultValueCount(); |
|
1090 |
|
1091 __ASSERT_ALWAYS(count == defaultValueCount+1, TUtil::Panic(KErrGeneral)); |
|
1092 |
|
1093 |
|
1094 CSelectableItem* item = (*aList)[count-1]; |
|
1095 |
|
1096 SetQueryValueTextL(item->ItemText()); |
|
1097 |
|
1098 if (!item->SelectionStatus()) |
|
1099 { |
|
1100 iProperty->UnselectQueryValueL(); |
|
1101 } |
|
1102 } |
|
1103 |
|
1104 |
|
1105 // ----------------------------------------------------------------------------- |
|
1106 // CAspFilterItem::AddQueryValueL |
|
1107 // |
|
1108 // ----------------------------------------------------------------------------- |
|
1109 // |
|
1110 void CAspFilterItem::AddQueryValueL(CSelectionItemList* aList) |
|
1111 { |
|
1112 if (iListType != ETypeSingleSelectionUserDefined && iListType != ETypeMultipleSelectionUserDefined) |
|
1113 { |
|
1114 return; |
|
1115 } |
|
1116 |
|
1117 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1118 if (type != ESyncMLDataTypeNumber && type != ESyncMLDataTypeText16 && type != ESyncMLDataTypeText8) |
|
1119 { |
|
1120 return; // "User defined" list only supports number and text |
|
1121 } |
|
1122 |
|
1123 |
|
1124 |
|
1125 TBuf<KBufSize> buf; |
|
1126 TBool selected = iProperty->IsQueryValueSelected(); |
|
1127 GetQueryValueTextL(buf); |
|
1128 |
|
1129 CSelectableItem* item = new (ELeave) CSelectableItem(buf, selected); |
|
1130 CleanupStack::PushL(item); |
|
1131 item->ConstructL(); |
|
1132 aList->AppendL(item); |
|
1133 CleanupStack::Pop(item); |
|
1134 } |
|
1135 |
|
1136 |
|
1137 // ----------------------------------------------------------------------------- |
|
1138 // CAspFilterItem::GetTextL |
|
1139 // |
|
1140 // ----------------------------------------------------------------------------- |
|
1141 // |
|
1142 void CAspFilterItem::GetTextL(TDes& aText) |
|
1143 { |
|
1144 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1145 |
|
1146 __ASSERT_DEBUG(type==ESyncMLDataTypeText8 || type==ESyncMLDataTypeText16, TUtil::Panic(KErrGeneral)); |
|
1147 |
|
1148 if (type == ESyncMLDataTypeText8) |
|
1149 { |
|
1150 TUtil::StrCopy(aText, iProperty->QueryValueText8L()); |
|
1151 } |
|
1152 else |
|
1153 { |
|
1154 TUtil::StrCopy(aText, iProperty->QueryValueText16L()); |
|
1155 } |
|
1156 } |
|
1157 |
|
1158 |
|
1159 // ----------------------------------------------------------------------------- |
|
1160 // CAspFilterItem::GetText |
|
1161 // |
|
1162 // ----------------------------------------------------------------------------- |
|
1163 // |
|
1164 void CAspFilterItem::GetText(TDes& aText) |
|
1165 { |
|
1166 TRAPD(err, GetTextL(aText)); |
|
1167 |
|
1168 if (err != KErrNone) |
|
1169 { |
|
1170 aText = KNullDesC; |
|
1171 } |
|
1172 } |
|
1173 |
|
1174 |
|
1175 // ----------------------------------------------------------------------------- |
|
1176 // CAspFilterItem::SetTextL |
|
1177 // |
|
1178 // ----------------------------------------------------------------------------- |
|
1179 // |
|
1180 void CAspFilterItem::SetTextL(const TDesC& aText) |
|
1181 { |
|
1182 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1183 |
|
1184 __ASSERT_DEBUG(type==ESyncMLDataTypeText8 || type==ESyncMLDataTypeText16, TUtil::Panic(KErrGeneral)); |
|
1185 |
|
1186 if (type == ESyncMLDataTypeText8) |
|
1187 { |
|
1188 TUtil::StrCopy(iBuf8, aText); |
|
1189 iProperty->SetQueryValueText8L(iBuf8); |
|
1190 } |
|
1191 else |
|
1192 { |
|
1193 iProperty->SetQueryValueText16L(aText); |
|
1194 } |
|
1195 } |
|
1196 |
|
1197 |
|
1198 // ----------------------------------------------------------------------------- |
|
1199 // CAspFilterItem::BoolL |
|
1200 // |
|
1201 // ----------------------------------------------------------------------------- |
|
1202 // |
|
1203 TBool CAspFilterItem::BoolL() |
|
1204 { |
|
1205 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1206 |
|
1207 __ASSERT_DEBUG(type==ESyncMLDataTypeBool, TUtil::Panic(KErrGeneral)); |
|
1208 |
|
1209 return iProperty->QueryValueBoolL(); |
|
1210 } |
|
1211 |
|
1212 |
|
1213 // ----------------------------------------------------------------------------- |
|
1214 // CAspFilterItem::SetBoolL |
|
1215 // |
|
1216 // ----------------------------------------------------------------------------- |
|
1217 // |
|
1218 void CAspFilterItem::SetBoolL(TBool aBool) |
|
1219 { |
|
1220 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1221 |
|
1222 __ASSERT_DEBUG(type==ESyncMLDataTypeBool, TUtil::Panic(KErrGeneral)); |
|
1223 |
|
1224 iProperty->SetQueryValueBoolL(aBool); |
|
1225 } |
|
1226 |
|
1227 |
|
1228 // ----------------------------------------------------------------------------- |
|
1229 // CAspFilterItem::IntL |
|
1230 // |
|
1231 // ----------------------------------------------------------------------------- |
|
1232 // |
|
1233 TInt CAspFilterItem::IntL() |
|
1234 { |
|
1235 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1236 |
|
1237 __ASSERT_DEBUG(type==ESyncMLDataTypeNumber, TUtil::Panic(KErrGeneral)); |
|
1238 |
|
1239 return iProperty->QueryValueIntL(); |
|
1240 } |
|
1241 |
|
1242 |
|
1243 // ----------------------------------------------------------------------------- |
|
1244 // CAspFilterItem::SetIntL |
|
1245 // |
|
1246 // ----------------------------------------------------------------------------- |
|
1247 // |
|
1248 void CAspFilterItem::SetIntL(TInt aInt) |
|
1249 { |
|
1250 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1251 |
|
1252 __ASSERT_DEBUG(type==ESyncMLDataTypeNumber, TUtil::Panic(KErrGeneral)); |
|
1253 |
|
1254 iProperty->SetQueryValueIntL(aInt); |
|
1255 } |
|
1256 |
|
1257 |
|
1258 // ----------------------------------------------------------------------------- |
|
1259 // CAspFilterItem::DateL |
|
1260 // |
|
1261 // ----------------------------------------------------------------------------- |
|
1262 // |
|
1263 TTime CAspFilterItem::DateL() |
|
1264 { |
|
1265 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1266 |
|
1267 __ASSERT_DEBUG(type==ESyncMLDataTypeDate, TUtil::Panic(KErrGeneral)); |
|
1268 |
|
1269 return iProperty->QueryValueDateL(); |
|
1270 } |
|
1271 |
|
1272 |
|
1273 // ----------------------------------------------------------------------------- |
|
1274 // CAspFilterItem::SetDateL |
|
1275 // |
|
1276 // ----------------------------------------------------------------------------- |
|
1277 // |
|
1278 void CAspFilterItem::SetDateL(TTime aTime) |
|
1279 { |
|
1280 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1281 |
|
1282 __ASSERT_DEBUG(type==ESyncMLDataTypeDate, TUtil::Panic(KErrGeneral)); |
|
1283 |
|
1284 return iProperty->SetQueryValueDateL(aTime); |
|
1285 } |
|
1286 |
|
1287 |
|
1288 // ----------------------------------------------------------------------------- |
|
1289 // CAspFilterItem::TimeL |
|
1290 // |
|
1291 // ----------------------------------------------------------------------------- |
|
1292 // |
|
1293 TTime CAspFilterItem::TimeL() |
|
1294 { |
|
1295 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1296 |
|
1297 __ASSERT_DEBUG(type==ESyncMLDataTypeTime, TUtil::Panic(KErrGeneral)); |
|
1298 |
|
1299 return iProperty->QueryValueTimeL(); |
|
1300 } |
|
1301 |
|
1302 |
|
1303 // ----------------------------------------------------------------------------- |
|
1304 // CAspFilterItem::SetTimeL |
|
1305 // |
|
1306 // ----------------------------------------------------------------------------- |
|
1307 // |
|
1308 void CAspFilterItem::SetTimeL(TTime aTime) |
|
1309 { |
|
1310 TSyncMLFilterPropertyDataType type = iProperty->QueryValueDataType(); |
|
1311 |
|
1312 __ASSERT_DEBUG(type==ESyncMLDataTypeTime, TUtil::Panic(KErrGeneral)); |
|
1313 |
|
1314 return iProperty->SetQueryValueTimeL(aTime); |
|
1315 } |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 // End of file |
|
1322 |