1 /* |
|
2 * Copyright (c) 2002 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 * Contact model ECOM sort plugin. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "ccntsortplugin.h" |
|
22 |
|
23 #include <SortUtil.h> |
|
24 #include <cntdef.h> |
|
25 |
|
26 #include "csortkeyarray.h" |
|
27 |
|
28 namespace { |
|
29 |
|
30 #ifdef _DEBUG |
|
31 enum TPanicType |
|
32 { |
|
33 EPanicPreCond_CompareViewContactsL = 1, |
|
34 EPanicSortUtilFactoryReturnedNULL, |
|
35 EPanicInvalidViewParameters, |
|
36 EPanicDefaultCompareFunctionNULL, |
|
37 EPanicDefaultIsSortableFunctionNULL |
|
38 }; |
|
39 |
|
40 void Panic(TPanicType aPanicType) |
|
41 { |
|
42 _LIT(KPanicTxt, "CCntSortPlugin"); |
|
43 User::Panic(KPanicTxt, aPanicType); |
|
44 } |
|
45 #endif |
|
46 } // namespace |
|
47 |
|
48 // ========================== MEMBER FUNCTIONS =============================== |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CCntSortPlugin::NewL |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CCntSortPlugin* CCntSortPlugin::NewL(TAny* aParams) |
|
55 { |
|
56 CCntSortPlugin* self = new(ELeave) CCntSortPlugin; |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(static_cast<TSortPluginParams*>(aParams)); |
|
59 CleanupStack::Pop(); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CCntSortPlugin::ConstructL |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void CCntSortPlugin::ConstructL(TSortPluginParams* aParams) |
|
68 { |
|
69 // Validate parameters |
|
70 if (!aParams || |
|
71 (aParams->iParametersRevision != KCntSortPluginViewParamsRev1Uid)) |
|
72 User::Leave(KErrArgument); |
|
73 |
|
74 TSortPluginViewParamsRev1* viewParams = |
|
75 static_cast<TSortPluginViewParamsRev1*>(aParams->iViewSortParams); |
|
76 |
|
77 __ASSERT_DEBUG(viewParams, |
|
78 Panic(EPanicInvalidViewParameters)); |
|
79 __ASSERT_DEBUG(viewParams->iCompareViewContactsL, |
|
80 Panic(EPanicDefaultCompareFunctionNULL)); |
|
81 __ASSERT_DEBUG(viewParams->iIsSortable, |
|
82 Panic(EPanicDefaultIsSortableFunctionNULL)); |
|
83 |
|
84 iIsSortable = viewParams->iIsSortable; |
|
85 |
|
86 iSortUtil = CSortUtil::NewL(); |
|
87 // Sort Util factory has to return valid pointer |
|
88 // Factory should default to european sorting if nothing else is |
|
89 // applicable |
|
90 __ASSERT_DEBUG(iSortUtil, Panic(EPanicSortUtilFactoryReturnedNULL)); |
|
91 |
|
92 iLeftSortKeyArray = CSortKeyArray::NewL(); |
|
93 iRightSortKeyArray = CSortKeyArray::NewL(); |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CCntSortPlugin::CCntSortPlugin |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 CCntSortPlugin::CCntSortPlugin() |
|
101 { |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CCntSortPlugin::~CCntSortPlugin |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 CCntSortPlugin::~CCntSortPlugin() |
|
109 { |
|
110 delete iSortUtil; |
|
111 iSortOrder.Close(); |
|
112 delete iLeftSortKeyArray; |
|
113 delete iRightSortKeyArray; |
|
114 } |
|
115 |
|
116 void CCntSortPlugin::SetSortOrderL |
|
117 (const RContactViewSortOrder& aViewSortOrder) |
|
118 { |
|
119 iSortOrder.Close(); |
|
120 iSortOrder.CopyL(aViewSortOrder); |
|
121 } |
|
122 |
|
123 TInt CCntSortPlugin::SortStart(TSortStartTypes aSortStartType, TInt aCount) |
|
124 { |
|
125 TRAPD(ret, DoSortStartL(aSortStartType, aCount)); |
|
126 return ret; |
|
127 } |
|
128 |
|
129 void CCntSortPlugin::DoSortStartL |
|
130 (TSortStartTypes /* aSortStartType */, TInt /* aCount */) |
|
131 { |
|
132 iLeftSortKeyArray->Reset(); |
|
133 iRightSortKeyArray->Reset(); |
|
134 |
|
135 const TInt count = iSortOrder.Count(); |
|
136 for (TInt i = 0; i < count; ++i) |
|
137 { |
|
138 TFieldType fieldType = iSortOrder[i]; |
|
139 if (fieldType == KUidContactFieldGivenNamePronunciation || |
|
140 fieldType == KUidContactFieldFamilyNamePronunciation || |
|
141 fieldType == KUidContactFieldCompanyNamePronunciation) |
|
142 { |
|
143 iLeftSortKeyArray->AppendL |
|
144 (TSortKey(KNullDesC, ESortKeyPronounciation)); |
|
145 iRightSortKeyArray->AppendL |
|
146 (TSortKey(KNullDesC, ESortKeyPronounciation)); |
|
147 } |
|
148 else |
|
149 { |
|
150 iLeftSortKeyArray->AppendL(TSortKey(KNullDesC, ESortKeyBasic)); |
|
151 iRightSortKeyArray->AppendL(TSortKey(KNullDesC, ESortKeyBasic)); |
|
152 } |
|
153 } |
|
154 } |
|
155 |
|
156 void CCntSortPlugin::SortCompleted() |
|
157 { |
|
158 iLeftSortKeyArray->Reset(); |
|
159 iRightSortKeyArray->Reset(); |
|
160 } |
|
161 |
|
162 TInt CCntSortPlugin::SortCompareViewContactsL |
|
163 (const CViewContact& aLhs, const CViewContact& aRhs) |
|
164 { |
|
165 __ASSERT_DEBUG(aLhs.FieldCount() == iSortOrder.Count(), |
|
166 Panic(EPanicPreCond_CompareViewContactsL)); |
|
167 __ASSERT_DEBUG(aRhs.FieldCount() == iSortOrder.Count(), |
|
168 Panic(EPanicPreCond_CompareViewContactsL)); |
|
169 __ASSERT_DEBUG(iLeftSortKeyArray && |
|
170 iLeftSortKeyArray->SortKeyCount() == iSortOrder.Count(), |
|
171 Panic(EPanicPreCond_CompareViewContactsL)); |
|
172 __ASSERT_DEBUG(iRightSortKeyArray && |
|
173 iRightSortKeyArray->SortKeyCount() == iSortOrder.Count(), |
|
174 Panic(EPanicPreCond_CompareViewContactsL)); |
|
175 |
|
176 // Change the text in the sortkeys to correspond fields in the contacts |
|
177 const TInt count = iSortOrder.Count(); |
|
178 for (TInt i = 0; i < count; ++i) |
|
179 { |
|
180 iLeftSortKeyArray->SetText(aLhs.Field(i), i); |
|
181 iRightSortKeyArray->SetText(aRhs.Field(i), i); |
|
182 } |
|
183 |
|
184 return iSortUtil->Interface()->CompareItems |
|
185 (*iLeftSortKeyArray, *iRightSortKeyArray); |
|
186 } |
|
187 |
|
188 TInt CCntSortPlugin::ApiCompareViewContactsL |
|
189 (const CViewContact& aLhs, const CViewContact& aRhs) |
|
190 { |
|
191 return SortCompareViewContactsL(aLhs, aRhs); |
|
192 } |
|
193 |
|
194 TBool CCntSortPlugin::ViewContactIsSortable |
|
195 (const CViewContact& aViewContact) |
|
196 { |
|
197 return iIsSortable(aViewContact); |
|
198 } |
|
199 |
|
200 // End of File |
|