author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:54:53 +0300 | |
branch | RCL_3 |
changeset 21 | 9da50d567e3c |
parent 20 | f4a778e096c2 |
permissions | -rw-r--r-- |
20 | 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: |
|
15 |
* Phonebook 2 contact view builder. |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
||
20 |
#include "CPbk2ContactViewBuilder.h" |
|
21 |
||
22 |
// Phonebook 2 |
|
23 |
#include "Pbk2PresentationUtils.h" |
|
24 |
#include "CPbk2StoreConfiguration.h" |
|
25 |
#include "CPbk2StoreProperty.h" |
|
26 |
#include "CPbk2StorePropertyArray.h" |
|
27 |
#include "CPbk2StoreViewDefinition.h" |
|
28 |
#include <RPbk2LocalizedResourceFile.h> |
|
21
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
29 |
#include <pbk2presentation.rsg> |
20 | 30 |
#include <Pbk2DataCaging.hrh> |
31 |
||
32 |
#include <CVPbkFieldTypeSelector.h> |
|
33 |
#include <VPbkContactViewFilterBuilder.h> |
|
34 |
||
35 |
// Virtual Phonebook |
|
36 |
#include <CVPbkContactStoreUriArray.h> |
|
37 |
#include <CVPbkContactViewDefinition.h> |
|
38 |
#include <CVPbkContactManager.h> |
|
39 |
#include <MVPbkContactViewBase.h> |
|
40 |
#include <MVPbkContactSelector.h> |
|
41 |
#include <VPbkContactView.hrh> |
|
42 |
||
43 |
// System includes |
|
44 |
#include <coemain.h> |
|
45 |
#include <barsread.h> |
|
46 |
||
47 |
// -------------------------------------------------------------------------- |
|
48 |
// CPbk2ContactViewBuilder::CPbk2ContactViewBuilder |
|
49 |
// -------------------------------------------------------------------------- |
|
50 |
// |
|
51 |
CPbk2ContactViewBuilder::CPbk2ContactViewBuilder( |
|
52 |
CVPbkContactManager& aContactManager, |
|
53 |
CPbk2StorePropertyArray& aStoreProperties ) : |
|
54 |
iContactManager( aContactManager ), |
|
55 |
iStoreProperties( aStoreProperties ) |
|
56 |
{ |
|
57 |
} |
|
58 |
||
59 |
// -------------------------------------------------------------------------- |
|
60 |
// CPbk2ContactViewBuilder::~CPbk2ContactViewBuilder |
|
61 |
// -------------------------------------------------------------------------- |
|
62 |
// |
|
63 |
CPbk2ContactViewBuilder::~CPbk2ContactViewBuilder() |
|
64 |
{ |
|
65 |
} |
|
66 |
||
67 |
// -------------------------------------------------------------------------- |
|
68 |
// CPbk2ContactViewBuilder::NewLC |
|
69 |
// -------------------------------------------------------------------------- |
|
70 |
// |
|
71 |
EXPORT_C CPbk2ContactViewBuilder* CPbk2ContactViewBuilder::NewLC( |
|
72 |
CVPbkContactManager& aContactManager, |
|
73 |
CPbk2StorePropertyArray& aStoreProperties ) |
|
74 |
{ |
|
75 |
CPbk2ContactViewBuilder* self = new ( ELeave ) CPbk2ContactViewBuilder( |
|
76 |
aContactManager, aStoreProperties ); |
|
77 |
CleanupStack::PushL( self ); |
|
78 |
return self; |
|
79 |
} |
|
80 |
||
81 |
// -------------------------------------------------------------------------- |
|
82 |
// CPbk2ContactViewBuilder::CreateContactViewForStoresLC |
|
83 |
// -------------------------------------------------------------------------- |
|
84 |
// |
|
85 |
EXPORT_C MVPbkContactViewBase* |
|
86 |
CPbk2ContactViewBuilder::CreateContactViewForStoresLC( |
|
87 |
const CVPbkContactStoreUriArray& aUriArray, |
|
88 |
MVPbkContactViewObserver& aObserver, |
|
89 |
const MVPbkFieldTypeList& aSortOrder, |
|
90 |
CVPbkFieldTypeSelector* aFilter, |
|
91 |
TUint32 aFlags ) const |
|
92 |
{ |
|
93 |
return CreateViewForStoresLC |
|
94 |
( EPbk2MainNamesList, aUriArray, aObserver, aSortOrder, aFilter, aFlags ); |
|
95 |
} |
|
96 |
||
97 |
// -------------------------------------------------------------------------- |
|
98 |
// CPbk2ContactViewBuilder::CreateContactViewForStoresLC |
|
99 |
// -------------------------------------------------------------------------- |
|
100 |
// |
|
101 |
EXPORT_C MVPbkContactViewBase* |
|
102 |
CPbk2ContactViewBuilder::CreateContactViewForStoresLC( |
|
103 |
const CVPbkContactStoreUriArray& aUriArray, |
|
104 |
MVPbkContactViewObserver& aObserver, |
|
105 |
const MVPbkFieldTypeList& aSortOrder, |
|
106 |
CVPbkFieldTypeSelector* aFilter, |
|
107 |
TUint32 aFlags, |
|
108 |
MVPbkContactSelector* aContactSelector) const |
|
109 |
{ |
|
110 |
return CreateViewForStoresLC |
|
111 |
( EPbk2MainNamesList, aUriArray, aObserver, aSortOrder, aFilter, aFlags, EFalse, aContactSelector ); |
|
112 |
} |
|
113 |
||
114 |
// -------------------------------------------------------------------------- |
|
115 |
// CPbk2ContactViewBuilder::CreateTopNonTopContactViewForStoresLC |
|
116 |
// |
|
117 |
// Similar as CreateContactViewForStoresLC but TopContacts are filtered out |
|
118 |
// -------------------------------------------------------------------------- |
|
119 |
// |
|
120 |
EXPORT_C MVPbkContactViewBase* |
|
121 |
CPbk2ContactViewBuilder::CreateTopNonTopContactViewForStoresLC( |
|
122 |
const CVPbkContactStoreUriArray& aUriArray, |
|
123 |
MVPbkContactViewObserver& aObserver, |
|
124 |
const MVPbkFieldTypeList& aSortOrder, |
|
125 |
CVPbkFieldTypeSelector* aFilter, |
|
126 |
TUint32 aFlags, |
|
127 |
MVPbkContactSelector& aContactSelector ) const |
|
128 |
{ |
|
129 |
iContactSelector = &aContactSelector; |
|
130 |
||
131 |
return CreateViewForStoresLC( |
|
132 |
EPbk2MainTopContactsList, // This param has no effect if aTopContacts=ETrue |
|
133 |
aUriArray, |
|
134 |
aObserver, |
|
135 |
aSortOrder, |
|
136 |
aFilter, |
|
137 |
aFlags, |
|
138 |
ETrue ); // aTopContacts = ETrue |
|
139 |
} |
|
140 |
||
141 |
// -------------------------------------------------------------------------- |
|
142 |
// CPbk2ContactViewBuilder::CreateGroupViewForStoresLC |
|
143 |
// -------------------------------------------------------------------------- |
|
144 |
// |
|
145 |
EXPORT_C MVPbkContactViewBase* |
|
146 |
CPbk2ContactViewBuilder::CreateGroupViewForStoresLC( |
|
147 |
const CVPbkContactStoreUriArray& aUriArray, |
|
148 |
MVPbkContactViewObserver& aObserver, |
|
149 |
const MVPbkFieldTypeList& aSortOrder, |
|
150 |
CVPbkFieldTypeSelector* aFilter, |
|
151 |
TUint32 aFlags ) const |
|
152 |
{ |
|
153 |
return CreateViewForStoresLC |
|
154 |
( EPbk2MainGroupsList, aUriArray, aObserver, aSortOrder, aFilter, aFlags ); |
|
155 |
} |
|
156 |
||
157 |
// -------------------------------------------------------------------------- |
|
158 |
// CPbk2ContactViewBuilder::BuildMainViewStructureLC |
|
159 |
// -------------------------------------------------------------------------- |
|
160 |
// |
|
161 |
CVPbkContactViewDefinition* |
|
162 |
CPbk2ContactViewBuilder::BuildMainViewStructureLC( |
|
163 |
CVPbkFieldTypeSelector* aFilter, |
|
164 |
TUint32 aFlags ) const |
|
165 |
{ |
|
166 |
RPbk2LocalizedResourceFile resFile( *CCoeEnv::Static() ); |
|
167 |
resFile.OpenLC( KPbk2RomFileDrive, |
|
168 |
KDC_RESOURCE_FILES_DIR, |
|
169 |
Pbk2PresentationUtils::PresentationResourceFile() ); |
|
170 |
||
171 |
TResourceReader reader; |
|
172 |
CCoeEnv::Static()->CreateResourceReaderLC |
|
173 |
( reader, R_PHONEBOOK2_MAIN_CONTACT_VIEW_STRUCTURE ); |
|
174 |
||
175 |
CVPbkContactViewDefinition* viewDef = |
|
176 |
CVPbkContactViewDefinition::NewL( reader ); |
|
177 |
CleanupStack::PopAndDestroy(2); // reader, resFile |
|
178 |
CleanupStack::PushL( viewDef ); |
|
179 |
||
180 |
if( aFlags & EVPbkExcludeEmptyGroups ) |
|
181 |
{ |
|
182 |
viewDef->SetFlag ( EVPbkExcludeEmptyGroups, ETrue ); |
|
183 |
} |
|
184 |
||
185 |
viewDef->SetFieldTypeFilterL( aFilter ); |
|
186 |
return viewDef; |
|
187 |
} |
|
188 |
||
189 |
// -------------------------------------------------------------------------- |
|
190 |
// CPbk2ContactViewBuilder::CreateViewForStoresLC |
|
191 |
// Creates a sub-view for all matching view types, from the listed stores. |
|
192 |
// -------------------------------------------------------------------------- |
|
193 |
// |
|
194 |
/** |
|
195 |
* Creates a sub-view for all matching view types from the listed stores. |
|
196 |
* @param aViewType The view type that should match. |
|
197 |
* @param aUriArray The Stores from which to look for views. |
|
198 |
* @param aObserver An observer |
|
199 |
* @param aSortOrder |
|
200 |
* @param aFilter An object that is able to discard contacts based on |
|
201 |
* field collection. |
|
202 |
* @param aTopContacts Whether or not to construct a top/non-top-contact style |
|
203 |
* of list, or a normal legacy list with no top contacts. |
|
204 |
* @return The actual new view. |
|
205 |
*/ |
|
206 |
MVPbkContactViewBase* CPbk2ContactViewBuilder::CreateViewForStoresLC( |
|
207 |
TPbk2ContactViewType aViewType, |
|
208 |
const CVPbkContactStoreUriArray& aUriArray, |
|
209 |
MVPbkContactViewObserver& aObserver, |
|
210 |
const MVPbkFieldTypeList& aSortOrder, |
|
211 |
CVPbkFieldTypeSelector* aFilter, |
|
212 |
TUint32 aFlags, |
|
213 |
TBool aTopContacts, |
|
214 |
MVPbkContactSelector* aContactSelector) const |
|
215 |
{ |
|
216 |
// Main view is a composite view that contains several sub composite |
|
217 |
// views. The subviews are identified by TPbk2ContactViewLocation. |
|
218 |
CVPbkContactViewDefinition* viewDef = BuildMainViewStructureLC( aFilter, aFlags ); |
|
219 |
||
220 |
const TInt count = aUriArray.Count(); |
|
221 |
for ( TInt i = 0; i < count; ++i ) |
|
222 |
{ |
|
223 |
// Get store property for each URI |
|
224 |
const CPbk2StoreProperty* storeProperty = |
|
225 |
iStoreProperties.FindProperty( aUriArray[i] ); |
|
226 |
if ( storeProperty ) |
|
227 |
{ |
|
228 |
// Loop all view definitions of the store and |
|
229 |
// add the view definitions to the correct sub view of |
|
230 |
// the main structure. |
|
231 |
TArray<const CPbk2StoreViewDefinition*> viewDefs = |
|
232 |
storeProperty->Views(); |
|
233 |
const TInt viewDefCount = viewDefs.Count(); |
|
234 |
for ( TInt j = 0; j < viewDefCount; ++j ) |
|
235 |
{ |
|
236 |
const CPbk2StoreViewDefinition* pb2ViewDef = viewDefs[j]; |
|
237 |
// Check that UI type of the view is the given type. |
|
238 |
// Meaning that does the view belong to all-contacts-view |
|
239 |
// or all-groups-view. |
|
240 |
||
241 |
TBool includeThisView = pb2ViewDef->ViewType() == aViewType; |
|
242 |
if ( aTopContacts ) |
|
243 |
{ |
|
244 |
includeThisView = IncludeThisViewInTopContactMode( pb2ViewDef->ViewType() ); |
|
245 |
} |
|
246 |
if ( includeThisView ) |
|
247 |
{ |
|
248 |
// Get the correct sub view of the main view structure. |
|
249 |
CVPbkContactViewDefinition& subView = viewDef->SubViewAt( |
|
250 |
TInt( pb2ViewDef->ViewLocation() ) ); |
|
251 |
// Add store's view to composite. |
|
252 |
CVPbkContactViewDefinition* newSubView = |
|
253 |
CVPbkContactViewDefinition::NewL( |
|
254 |
pb2ViewDef->ViewDefinition() ); |
|
255 |
CleanupStack::PushL( newSubView ); |
|
256 |
if ( aTopContacts ) |
|
257 |
{ |
|
258 |
SetTopRelatedFilteringL( |
|
259 |
*newSubView, pb2ViewDef->ViewType(), aFilter ); |
|
260 |
} |
|
261 |
else |
|
262 |
{ |
|
263 |
newSubView->SetFieldTypeFilterL( aFilter ); |
|
264 |
} |
|
265 |
if( aFlags & EVPbkExcludeEmptyGroups ) |
|
266 |
{ |
|
267 |
newSubView->SetFlag ( EVPbkExcludeEmptyGroups, ETrue ); |
|
268 |
} |
|
269 |
||
270 |
if( aFlags & EVPbkExcludeEmptyGroups ) |
|
271 |
{ |
|
272 |
newSubView->SetFlag ( EVPbkExcludeEmptyGroups, ETrue ); |
|
273 |
} |
|
274 |
if( !(newSubView->ContactSelector()) ) |
|
275 |
{ |
|
276 |
newSubView->SetContactSelector( aContactSelector ); |
|
277 |
} |
|
278 |
||
279 |
subView.AddSubViewL( newSubView ); |
|
280 |
CleanupStack::Pop(); |
|
281 |
} |
|
282 |
} |
|
283 |
} |
|
284 |
} |
|
285 |
||
286 |
MVPbkContactViewBase* result = iContactManager.CreateContactViewLC |
|
287 |
( aObserver, *viewDef, aSortOrder ); |
|
288 |
CleanupStack::Pop(); // result |
|
289 |
||
290 |
CleanupStack::PopAndDestroy(); // viewDef |
|
291 |
CleanupDeletePushL( result ); |
|
292 |
return result; |
|
293 |
} |
|
294 |
||
295 |
||
296 |
TBool CPbk2ContactViewBuilder::IncludeThisViewInTopContactMode( |
|
297 |
TPbk2ContactViewType aViewType ) |
|
298 |
{ |
|
299 |
return aViewType == EPbk2MainTopContactsList || aViewType == EPbk2MainNamesList; |
|
300 |
} |
|
301 |
||
302 |
void CPbk2ContactViewBuilder::SetTopRelatedFilteringL( |
|
303 |
CVPbkContactViewDefinition& aNewSubViewDef, |
|
304 |
TPbk2ContactViewType aViewType, |
|
305 |
CVPbkFieldTypeSelector* aFilter ) const |
|
306 |
{ |
|
307 |
if ( aViewType == EPbk2MainTopContactsList ) |
|
308 |
{ |
|
309 |
//Override original filter with top contact filter. |
|
310 |
CVPbkFieldTypeSelector* filter = CVPbkFieldTypeSelector::NewL( |
|
311 |
iContactManager.FieldTypes()); |
|
312 |
CleanupStack::PushL(filter); |
|
313 |
||
314 |
//Set the filter to retrieve Top contact items (VPbkContactView.hrh) |
|
315 |
VPbkContactViewFilterBuilder::BuildContactViewFilterL( *filter, |
|
316 |
TVPbkContactViewFilter(EVPbkContactViewFilterTopContact), iContactManager ); |
|
317 |
aNewSubViewDef.SetFieldTypeFilterL( filter ); |
|
318 |
CleanupStack::PopAndDestroy(); //filter |
|
319 |
} |
|
320 |
else if ( aViewType == EPbk2MainNamesList ) |
|
321 |
{ |
|
322 |
//Use original filter, if any |
|
323 |
aNewSubViewDef.SetFieldTypeFilterL( aFilter ); |
|
324 |
if ( iContactSelector ) |
|
325 |
{ |
|
326 |
// Add the contact selector |
|
327 |
// (usually the Non-Top Contacts selector) |
|
328 |
aNewSubViewDef.SetContactSelector( iContactSelector ); // ownership not transferred |
|
329 |
} |
|
330 |
} |
|
331 |
else |
|
332 |
{ |
|
333 |
//Use original filter, if any |
|
334 |
aNewSubViewDef.SetFieldTypeFilterL( aFilter ); |
|
335 |
} |
|
336 |
} |
|
337 |
||
338 |
// End of File |