63
|
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: Contacts Model store custom filtered contact
|
|
15 |
* view implementation. Derives from MVPbkContactViewBase,
|
|
16 |
* performs the custom filtering.
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
|
|
21 |
#include "CCustomFilteredGroupView.h"
|
|
22 |
|
|
23 |
// VPbkCntModel
|
|
24 |
#include "CContactStore.h"
|
|
25 |
#include "CContact.h"
|
|
26 |
#include "cntitem.h"
|
|
27 |
#include "CCustomFilteredNativeContactView.h"
|
|
28 |
|
|
29 |
// VPbkEng
|
|
30 |
#include <MVPbkFieldTypeSelector.h>
|
|
31 |
#include <CVPbkFilteredContactView.h>
|
|
32 |
#include <MVPbkContactLinkArray.h>
|
|
33 |
#include <CVPbkContactViewDefinition.h>
|
|
34 |
|
|
35 |
|
|
36 |
namespace VPbkCntModel {
|
|
37 |
|
|
38 |
// --------------------------------------------------------------------------
|
|
39 |
// CCustomFilteredGroupView::CCustomFilteredGroupView
|
|
40 |
// --------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
CCustomFilteredGroupView::CCustomFilteredGroupView
|
|
43 |
( CContactStore& aContactStore,
|
|
44 |
const MVPbkFieldTypeSelector* aFieldTypeSelector,
|
|
45 |
MCustomContactViewObserver& aCustomContactViewObserver ) :
|
|
46 |
CViewBase( aContactStore ),
|
|
47 |
iContactStore( aContactStore ),
|
|
48 |
iFieldTypeSelector( aFieldTypeSelector ),
|
|
49 |
iCustomContactViewObserver( aCustomContactViewObserver )
|
|
50 |
{
|
|
51 |
}
|
|
52 |
|
|
53 |
// --------------------------------------------------------------------------
|
|
54 |
// CCustomFilteredGroupView::ConstructL
|
|
55 |
// --------------------------------------------------------------------------
|
|
56 |
//
|
|
57 |
void CCustomFilteredGroupView::ConstructL(
|
|
58 |
const CVPbkContactViewDefinition& aViewDefinition,
|
|
59 |
MVPbkContactViewObserver& aViewObserver,
|
|
60 |
const MVPbkFieldTypeList& aSortOrder,
|
|
61 |
CContactViewBase& aNativeViewBase)
|
|
62 |
{
|
|
63 |
// iView should be assign first because is used by base class during the
|
|
64 |
// construction.
|
|
65 |
iView = &aNativeViewBase;
|
|
66 |
ConstructL( aViewDefinition, aViewObserver, aSortOrder );
|
|
67 |
// Set the customically filtered view parameters
|
|
68 |
iCustomFilteredContactView->SetNativeBaseView( aNativeViewBase );
|
|
69 |
}
|
|
70 |
|
|
71 |
// --------------------------------------------------------------------------
|
|
72 |
// CCustomFilteredGroupView::~CCustomFilteredGroupView
|
|
73 |
// --------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
CCustomFilteredGroupView::~CCustomFilteredGroupView()
|
|
76 |
{
|
|
77 |
delete iCustomFilteredContactView;
|
|
78 |
delete iFilteredView;
|
|
79 |
}
|
|
80 |
|
|
81 |
// --------------------------------------------------------------------------
|
|
82 |
// CCustomFilteredGroupView::ConstructL
|
|
83 |
// --------------------------------------------------------------------------
|
|
84 |
//
|
|
85 |
void CCustomFilteredGroupView::ConstructL(
|
|
86 |
const CVPbkContactViewDefinition& aViewDefinition,
|
|
87 |
MVPbkContactViewObserver& aObserver,
|
|
88 |
const MVPbkFieldTypeList& aSortOrder )
|
|
89 |
{
|
|
90 |
// Base construct has to be done first
|
|
91 |
CViewBase::ConstructL( aViewDefinition, aSortOrder );
|
|
92 |
|
|
93 |
// Construct the custom filtered native view
|
|
94 |
iCustomFilteredContactView = CCustomFilteredNativeContactView::NewL
|
|
95 |
( iContactStore );
|
|
96 |
|
|
97 |
// This object is the base view and contact selector
|
|
98 |
// for the Virtual Phonebook filtered view. The base view calls
|
|
99 |
// are handled by CViewBase.
|
|
100 |
// The selector logic is implemented here in this class.
|
|
101 |
iFilteredView = CVPbkFilteredContactView::NewL
|
|
102 |
( *this, aObserver, *this );
|
|
103 |
iCustomFilteredContactView->SetCustomFilterView( *iFilteredView );
|
|
104 |
}
|
|
105 |
|
|
106 |
// --------------------------------------------------------------------------
|
|
107 |
// CCustomFilteredGroupView::ContactViewBase
|
|
108 |
// --------------------------------------------------------------------------
|
|
109 |
//
|
|
110 |
CContactViewBase& CCustomFilteredGroupView::ContactViewBase()
|
|
111 |
{
|
|
112 |
return *iCustomFilteredContactView;
|
|
113 |
}
|
|
114 |
|
|
115 |
// --------------------------------------------------------------------------
|
|
116 |
// CCustomFilteredGroupView::Type
|
|
117 |
// --------------------------------------------------------------------------
|
|
118 |
//
|
|
119 |
TVPbkContactViewType CCustomFilteredGroupView::Type() const
|
|
120 |
{
|
|
121 |
return EVPbkGroupsView;
|
|
122 |
}
|
|
123 |
|
|
124 |
// --------------------------------------------------------------------------
|
|
125 |
// CCustomFilteredGroupView::DoInitializeViewL
|
|
126 |
// --------------------------------------------------------------------------
|
|
127 |
//
|
|
128 |
void CCustomFilteredGroupView::DoInitializeViewL(
|
|
129 |
const CVPbkContactViewDefinition& /*aViewDefinition*/,
|
|
130 |
RContactViewSortOrder& /*aViewSortOrder*/ )
|
|
131 |
{
|
|
132 |
// Required view initialization is already done
|
|
133 |
}
|
|
134 |
|
|
135 |
// --------------------------------------------------------------------------
|
|
136 |
// CCustomFilteredGroupView::DoTeardownView
|
|
137 |
// --------------------------------------------------------------------------
|
|
138 |
//
|
|
139 |
void CCustomFilteredGroupView::DoTeardownView()
|
|
140 |
{
|
|
141 |
/// Do nothing
|
|
142 |
}
|
|
143 |
|
|
144 |
// --------------------------------------------------------------------------
|
|
145 |
// CCustomFilteredGroupView::DoChangeSortOrderL
|
|
146 |
// --------------------------------------------------------------------------
|
|
147 |
//
|
|
148 |
TBool CCustomFilteredGroupView::DoChangeSortOrderL(
|
|
149 |
const CVPbkContactViewDefinition& /*aViewDefinition*/,
|
|
150 |
RContactViewSortOrder& /*aSortOrder*/ )
|
|
151 |
{
|
|
152 |
// Sort order not changed.
|
|
153 |
return EFalse;
|
|
154 |
}
|
|
155 |
|
|
156 |
// --------------------------------------------------------------------------
|
|
157 |
// CCustomFilteredGroupView::IsContactIncluded
|
|
158 |
// --------------------------------------------------------------------------
|
|
159 |
//
|
|
160 |
TBool CCustomFilteredGroupView::IsContactIncluded
|
|
161 |
( const MVPbkBaseContact& aContact )
|
|
162 |
{
|
|
163 |
TBool ret = EFalse;
|
|
164 |
|
|
165 |
// In case of an error, ignore it.
|
|
166 |
// The contact will then not be included in the view
|
|
167 |
TRAP_IGNORE(
|
|
168 |
ret = IsContactIncludedL( aContact )
|
|
169 |
);
|
|
170 |
|
|
171 |
return ret;
|
|
172 |
}
|
|
173 |
|
|
174 |
// --------------------------------------------------------------------------
|
|
175 |
// CCustomFilteredGroupView::HandleContactViewEvent
|
|
176 |
// --------------------------------------------------------------------------
|
|
177 |
//
|
|
178 |
void CCustomFilteredGroupView::HandleContactViewEvent
|
|
179 |
( const CContactViewBase& aView,
|
|
180 |
const TContactViewEvent& aEvent )
|
|
181 |
{
|
|
182 |
// Notify the custom view observer first
|
|
183 |
iCustomContactViewObserver.HandleCustomContactViewEvent( aView, aEvent );
|
|
184 |
CViewBase::HandleContactViewEvent( aView, aEvent );
|
|
185 |
}
|
|
186 |
|
|
187 |
// --------------------------------------------------------------------------
|
|
188 |
// CCustomFilteredGroupView::IsContactFieldIncludedL
|
|
189 |
// --------------------------------------------------------------------------
|
|
190 |
//
|
|
191 |
inline TBool CCustomFilteredGroupView::IsContactFieldIncludedL(
|
|
192 |
const CContactIdArray* aGroupMembers,
|
|
193 |
const TInt& aMemberCount,
|
|
194 |
const MVPbkFieldTypeSelector& aFieldTypeSelector )
|
|
195 |
{
|
|
196 |
TBool ret = EFalse;
|
|
197 |
|
|
198 |
for ( TInt i=0; i < aMemberCount && !ret; ++i )
|
|
199 |
{
|
|
200 |
const TContactItemId contactId = ( *aGroupMembers )[i];
|
|
201 |
CContactItem* item = iContactStore.NativeDatabase().
|
|
202 |
ReadContactLC( contactId ) ;
|
|
203 |
|
|
204 |
// Make a VPbk store contact
|
|
205 |
CContact* contact = CContact::NewL( iContactStore, item );
|
|
206 |
CleanupStack::Pop( item ); // ownership was taken away
|
|
207 |
CleanupStack::PushL( contact );
|
|
208 |
|
|
209 |
MVPbkStoreContactFieldCollection& fields = contact->Fields();
|
|
210 |
TInt fieldCount = fields.FieldCount();
|
|
211 |
|
|
212 |
for ( TInt i = 0; i < fieldCount; ++i )
|
|
213 |
{
|
|
214 |
const MVPbkStoreContactField& field = fields.FieldAt( i );
|
|
215 |
const MVPbkFieldType* fieldType = field.BestMatchingFieldType();
|
|
216 |
if ( fieldType &&
|
|
217 |
aFieldTypeSelector.IsFieldTypeIncluded( *fieldType ) )
|
|
218 |
{
|
|
219 |
ret = ETrue;
|
|
220 |
break;
|
|
221 |
}
|
|
222 |
}
|
|
223 |
|
|
224 |
CleanupStack::PopAndDestroy( contact );
|
|
225 |
}
|
|
226 |
|
|
227 |
return ret;
|
|
228 |
}
|
|
229 |
|
|
230 |
// --------------------------------------------------------------------------
|
|
231 |
// CCustomFilteredGroupView::IsContactIncludedL
|
|
232 |
// --------------------------------------------------------------------------
|
|
233 |
//
|
|
234 |
inline TBool CCustomFilteredGroupView::IsContactIncludedL
|
|
235 |
( const MVPbkBaseContact& aContact )
|
|
236 |
{
|
|
237 |
TBool ret = EFalse;
|
|
238 |
|
|
239 |
// First we have to get the contact id
|
|
240 |
const CViewContact& viewContact =
|
|
241 |
static_cast<const CViewContact&>( aContact );
|
|
242 |
TContactItemId id = viewContact.Id();
|
|
243 |
|
|
244 |
// Then we have to load the native contact group
|
|
245 |
CContactGroup* group = static_cast<CContactGroup*>
|
|
246 |
( iContactStore.NativeDatabase().ReadContactLC( id ) );
|
|
247 |
|
|
248 |
const CContactIdArray* groupMembers = group->ItemsContained();
|
|
249 |
if ( groupMembers )
|
|
250 |
{
|
|
251 |
CVPbkContactViewDefinition& viewDefinition = ViewDefinition();
|
|
252 |
const TInt memberCount = groupMembers->Count();
|
|
253 |
|
|
254 |
if( memberCount > 0 )
|
|
255 |
{
|
|
256 |
if( iFieldTypeSelector )
|
|
257 |
{
|
|
258 |
ret = IsContactFieldIncludedL( groupMembers, memberCount, *iFieldTypeSelector );
|
|
259 |
}
|
|
260 |
else
|
|
261 |
{
|
|
262 |
// No group filter given, so group is included no matter what
|
|
263 |
ret = ETrue;
|
|
264 |
}
|
|
265 |
}
|
|
266 |
else if( !viewDefinition.FlagIsOn( EVPbkExcludeEmptyGroups ) )
|
|
267 |
{
|
|
268 |
ret = ETrue;
|
|
269 |
}
|
|
270 |
}
|
|
271 |
|
|
272 |
CleanupStack::PopAndDestroy( group );
|
|
273 |
|
|
274 |
return ret;
|
|
275 |
}
|
|
276 |
|
|
277 |
} // namespace VPbkCntModel
|
|
278 |
|
|
279 |
// End of File
|