|
1 /* |
|
2 * Copyright (c) 2002-2007 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: Ordered composite contact view. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CVPbkOrderedCompositeContactView.h" |
|
20 |
|
21 // Debugging headers |
|
22 #include <VPbkProfile.h> |
|
23 |
|
24 // -------------------------------------------------------------------------- |
|
25 // CVPbkOrderedCompositeContactView::CVPbkOrderedCompositeContactView |
|
26 // -------------------------------------------------------------------------- |
|
27 // |
|
28 inline CVPbkOrderedCompositeContactView::CVPbkOrderedCompositeContactView() |
|
29 { |
|
30 } |
|
31 |
|
32 // -------------------------------------------------------------------------- |
|
33 // CVPbkOrderedCompositeContactView::NewLC |
|
34 // -------------------------------------------------------------------------- |
|
35 // |
|
36 CVPbkOrderedCompositeContactView* CVPbkOrderedCompositeContactView::NewLC( |
|
37 MVPbkContactViewObserver& aObserver, |
|
38 const MVPbkFieldTypeList& aSortOrder) |
|
39 { |
|
40 CVPbkOrderedCompositeContactView* self = |
|
41 new(ELeave) CVPbkOrderedCompositeContactView; |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(aSortOrder); |
|
44 self->AddObserverL(aObserver); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // -------------------------------------------------------------------------- |
|
49 // CVPbkOrderedCompositeContactView::ConstructL |
|
50 // -------------------------------------------------------------------------- |
|
51 // |
|
52 inline void CVPbkOrderedCompositeContactView::ConstructL |
|
53 (const MVPbkFieldTypeList& aSortOrder) |
|
54 { |
|
55 BaseConstructL(aSortOrder); |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CVPbkOrderedCompositeContactView::CreateFilteredViewLC |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 MVPbkContactViewBase* |
|
63 CVPbkOrderedCompositeContactView::CreateFilteredViewLC( |
|
64 MVPbkContactViewObserver& aObserver, |
|
65 const MDesCArray& aFindWords, |
|
66 const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts ) |
|
67 { |
|
68 CVPbkOrderedCompositeContactView* compositeView = |
|
69 CVPbkOrderedCompositeContactView::NewLC( |
|
70 aObserver, SortOrder() ); |
|
71 |
|
72 // If this composite is internal composite view then also |
|
73 // the created composite is internal. |
|
74 if ( CompositePolicy().InternalPolicy() ) |
|
75 { |
|
76 compositeView->ApplyInternalCompositePolicyL(); |
|
77 } |
|
78 |
|
79 const TInt count( iSubViews.Count() ); |
|
80 for( TInt i(0); i < count; ++i ) |
|
81 { |
|
82 MVPbkContactViewFiltering* filtering = |
|
83 iSubViews[i]->iView->ViewFiltering(); |
|
84 if ( filtering ) |
|
85 { |
|
86 MVPbkContactViewBase* filteredSubView = |
|
87 filtering->CreateFilteredViewLC( *compositeView, |
|
88 aFindWords, aAlwaysIncludedContacts ); |
|
89 compositeView->AddSubViewL( filteredSubView ); |
|
90 CleanupStack::Pop(); //filteredSubView |
|
91 } |
|
92 } |
|
93 return compositeView; |
|
94 } |
|
95 |
|
96 // -------------------------------------------------------------------------- |
|
97 // CVPbkOrderedCompositeContactView::DoBuildContactMappingL |
|
98 // Builds view mapping. |
|
99 // -------------------------------------------------------------------------- |
|
100 // |
|
101 void CVPbkOrderedCompositeContactView::DoBuildContactMappingL() |
|
102 { |
|
103 VPBK_PROFILE_START(VPbkProfile::EOrderedCompositeViewMapping); |
|
104 // Reset the mappings |
|
105 iContactMapping.Reset(); |
|
106 |
|
107 TContactMapping contactMapping; |
|
108 const TInt viewCount = iSubViews.Count(); |
|
109 for (TInt i = 0; i < viewCount; ++i) |
|
110 { |
|
111 // Ignore not ready views |
|
112 if (iSubViews[i]->iState != CSubViewData::EReady) |
|
113 { |
|
114 continue; |
|
115 } |
|
116 |
|
117 // Build mapping |
|
118 contactMapping.iViewIndex = i; |
|
119 const TInt contactCount = iSubViews[i]->iView->ContactCountL(); |
|
120 for (TInt j = 0; j < contactCount; ++j) |
|
121 { |
|
122 contactMapping.iContactIndex = j; |
|
123 User::LeaveIfError(iContactMapping.Append(contactMapping)); |
|
124 } |
|
125 } |
|
126 VPBK_PROFILE_END(VPbkProfile::EOrderedCompositeViewMapping); |
|
127 } |
|
128 |
|
129 // -------------------------------------------------------------------------- |
|
130 // CVPbkOrderedCompositeContactView::DoHandleContactAdditionL |
|
131 // Handles contact addition to the view. |
|
132 // -------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CVPbkOrderedCompositeContactView::DoHandleContactAdditionL |
|
135 (TInt aSubViewIndex, TInt aIndex) |
|
136 { |
|
137 TInt index = KErrNotFound; |
|
138 |
|
139 if (aSubViewIndex != KErrNotFound) |
|
140 { |
|
141 // Build mapping |
|
142 TContactMapping mapping; |
|
143 mapping.iViewIndex = aSubViewIndex; |
|
144 mapping.iContactIndex = aIndex; |
|
145 |
|
146 // Insert in order |
|
147 User::LeaveIfError( iContactMapping.InsertInOrderAllowRepeats |
|
148 ( mapping, |
|
149 &CVPbkOrderedCompositeContactView::CompareOrderedMappings ) ); |
|
150 |
|
151 // Find out the new index |
|
152 TIdentityRelation<TContactMapping> comparisonOperator |
|
153 ( &CVPbkCompositeContactView::CompareMappings ); |
|
154 index = iContactMapping.Find( mapping, comparisonOperator ); |
|
155 } |
|
156 |
|
157 return index; |
|
158 } |
|
159 |
|
160 // -------------------------------------------------------------------------- |
|
161 // CVPbkOrderedCompositeContactView::CompareOrderedMappings |
|
162 // Comparison function for the mappings. |
|
163 // Returns zero if the mappings are the same. Returns a negative value |
|
164 // if aLhs comes first and positive if aRhs comes first. |
|
165 // -------------------------------------------------------------------------- |
|
166 // |
|
167 TInt CVPbkOrderedCompositeContactView::CompareOrderedMappings |
|
168 ( const TContactMapping& aLhs, const TContactMapping& aRhs ) |
|
169 { |
|
170 // First compare view indexes |
|
171 TInt ret = aLhs.iViewIndex - aRhs.iViewIndex; |
|
172 |
|
173 if ( ret == 0 ) |
|
174 { |
|
175 // If view indexes are the same, then compare the contact indexes |
|
176 ret = aLhs.iContactIndex - aRhs.iContactIndex; |
|
177 } |
|
178 |
|
179 return ret; |
|
180 } |
|
181 |
|
182 // End of File |