63
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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: Phonebook 2 server application contact store manager.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "CPbk2ServerAppStoreManager.h"
|
|
20 |
|
|
21 |
// Phonebook 2
|
|
22 |
#include "mpbk2serverappstartupobserver.h"
|
|
23 |
#include "CPbk2ServerAppMonitor.h"
|
|
24 |
#include "CPbk2ServerAppAppUi.h"
|
|
25 |
#include <CPbk2StoreProperty.h>
|
|
26 |
#include <CPbk2StorePropertyArray.h>
|
|
27 |
#include <CPbk2StoreManager.h>
|
|
28 |
#include <CPbk2ContactViewBuilder.h>
|
|
29 |
#include <CPbk2StoreConfiguration.h>
|
|
30 |
#include <CPbk2SortOrderManager.h>
|
|
31 |
#include <Pbk2StoreProperty.hrh>
|
|
32 |
|
|
33 |
// Virtual Phonebook
|
|
34 |
#include <CVPbkContactManager.h>
|
|
35 |
#include <CVPbkContactStoreUriArray.h>
|
|
36 |
#include <MVPbkContactStore.h>
|
|
37 |
#include <MVPbkStoreContact.h>
|
|
38 |
#include <MVPbkContactStoreProperties.h>
|
|
39 |
#include <VPbkContactStoreUris.h>
|
|
40 |
#include <MVPbkContactViewBase.h>
|
|
41 |
#include <MVPbkContactLink.h>
|
|
42 |
#include <MVPbkContactLinkArray.h>
|
|
43 |
#include <CVPbkSortOrderAcquirer.h>
|
|
44 |
#include <VPbkSortOrderAcquirerUid.h>
|
|
45 |
#include <MVPbkBaseContact.h>
|
|
46 |
#include <MVPbkContactSelector.h>
|
|
47 |
|
|
48 |
// Debugging headers
|
|
49 |
#include <Pbk2Debug.h>
|
|
50 |
|
|
51 |
/// Unnamed namespace for local definitions
|
|
52 |
namespace {
|
|
53 |
|
|
54 |
_LIT( KGroupSortOrderDisplayName, "AllGroups" );
|
|
55 |
|
|
56 |
/**
|
|
57 |
* Custom cleanup function.
|
|
58 |
*
|
|
59 |
* @param aObj Object to clean.
|
|
60 |
*/
|
|
61 |
void CleanupResetAndDestroy( TAny* aObj )
|
|
62 |
{
|
|
63 |
if ( aObj )
|
|
64 |
{
|
|
65 |
static_cast<RImplInfoPtrArray*>( aObj )->ResetAndDestroy();
|
|
66 |
}
|
|
67 |
}
|
|
68 |
|
|
69 |
} /// namespace
|
|
70 |
|
|
71 |
|
|
72 |
// --------------------------------------------------------------------------
|
|
73 |
// CPbk2ServerAppStoreManager::CPbk2ServerAppStoreManager
|
|
74 |
// --------------------------------------------------------------------------
|
|
75 |
//
|
|
76 |
CPbk2ServerAppStoreManager::CPbk2ServerAppStoreManager
|
|
77 |
( CPbk2StoreManager& aStoreManager,
|
|
78 |
CVPbkContactManager& aContactManager ) :
|
|
79 |
iStoreManager( aStoreManager ),
|
|
80 |
iContactManager( aContactManager )
|
|
81 |
{
|
|
82 |
}
|
|
83 |
|
|
84 |
// --------------------------------------------------------------------------
|
|
85 |
// CPbk2ServerAppStoreManager::~CPbk2ServerAppStoreManager
|
|
86 |
// --------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
CPbk2ServerAppStoreManager::~CPbk2ServerAppStoreManager()
|
|
89 |
{
|
|
90 |
iStoreManager.DeregisterStoreEvents( *this );
|
|
91 |
iOpenedStores.Reset();
|
|
92 |
iOpenedStores.Close();
|
|
93 |
delete iSortOrderAcquirer;
|
|
94 |
delete iMonitor;
|
|
95 |
delete iFetchView;
|
|
96 |
}
|
|
97 |
|
|
98 |
// --------------------------------------------------------------------------
|
|
99 |
// CPbk2ServerAppStoreManager::ConstructL
|
|
100 |
// --------------------------------------------------------------------------
|
|
101 |
//
|
|
102 |
void CPbk2ServerAppStoreManager::ConstructL()
|
|
103 |
{
|
|
104 |
iStoreManager.RegisterStoreEventsL( *this );
|
|
105 |
}
|
|
106 |
|
|
107 |
// --------------------------------------------------------------------------
|
|
108 |
// CPbk2ServerAppStoreManager::NewL
|
|
109 |
// --------------------------------------------------------------------------
|
|
110 |
//
|
|
111 |
CPbk2ServerAppStoreManager* CPbk2ServerAppStoreManager::NewL
|
|
112 |
( CPbk2StoreManager& aStoreManager,
|
|
113 |
CVPbkContactManager& aContactManager )
|
|
114 |
{
|
|
115 |
CPbk2ServerAppStoreManager* self =
|
|
116 |
new ( ELeave ) CPbk2ServerAppStoreManager
|
|
117 |
( aStoreManager, aContactManager );
|
|
118 |
CleanupStack::PushL( self );
|
|
119 |
self->ConstructL();
|
|
120 |
CleanupStack::Pop( self );
|
|
121 |
return self;
|
|
122 |
}
|
|
123 |
|
|
124 |
// --------------------------------------------------------------------------
|
|
125 |
// CPbk2ServerAppStoreManager::LoadAndOpenContactStoresL
|
|
126 |
// --------------------------------------------------------------------------
|
|
127 |
//
|
|
128 |
void CPbk2ServerAppStoreManager::LoadAndOpenContactStoresL
|
|
129 |
( CVPbkContactStoreUriArray& aStoreUris,
|
|
130 |
MPbk2ServerAppStartupObserver& aObserver,
|
|
131 |
TBool aLoadSavingMemoriesAlways )
|
|
132 |
{
|
|
133 |
if ( aLoadSavingMemoriesAlways )
|
|
134 |
{
|
|
135 |
TVPbkContactStoreUriPtr ptr
|
|
136 |
( VPbkContactStoreUris::DefaultCntDbUri() );
|
|
137 |
if ( !aStoreUris.IsIncluded( ptr ) )
|
|
138 |
{
|
|
139 |
iContactManager.LoadContactStoreL( ptr );
|
|
140 |
}
|
|
141 |
iStoreManager.EnsureDefaultSavingStoreIncludedL();
|
|
142 |
}
|
|
143 |
|
|
144 |
const TInt count( aStoreUris.Count() );
|
|
145 |
for ( TInt i = 0; i < count; ++i )
|
|
146 |
{
|
|
147 |
iContactManager.LoadContactStoreL( aStoreUris[i] );
|
|
148 |
}
|
|
149 |
|
|
150 |
iMonitor = CPbk2ServerAppMonitor::NewL
|
|
151 |
( iContactManager.ContactStoresL(), aObserver );
|
|
152 |
iMonitor->RegisterEventsL( aObserver );
|
|
153 |
iMonitor->StartupBeginsL();
|
|
154 |
|
|
155 |
iStoreManager.OpenStoresL();
|
|
156 |
}
|
|
157 |
|
|
158 |
// --------------------------------------------------------------------------
|
|
159 |
// CPbk2ServerAppStoreManager::BuildFetchViewL
|
|
160 |
// --------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
MVPbkContactViewBase* CPbk2ServerAppStoreManager::BuildFetchViewL
|
|
163 |
( TVPbkContactViewType aViewType,
|
|
164 |
const CVPbkContactStoreUriArray& aStoreUris,
|
|
165 |
CVPbkFieldTypeSelector* aViewFilter,
|
|
166 |
CPbk2StorePropertyArray& aStoreProperties,
|
|
167 |
const CPbk2SortOrderManager& aSortOrderManager,
|
|
168 |
const TUint32 aFlags )
|
|
169 |
{
|
|
170 |
MVPbkContactViewBase* result = NULL;
|
|
171 |
|
|
172 |
CPbk2ContactViewBuilder* viewBuilder = CPbk2ContactViewBuilder::NewLC
|
|
173 |
( iContactManager, aStoreProperties );
|
|
174 |
|
|
175 |
if ( aViewType == EVPbkContactsView )
|
|
176 |
{
|
|
177 |
result = viewBuilder->CreateContactViewForStoresLC
|
|
178 |
( aStoreUris, *this, aSortOrderManager.SortOrder(),
|
|
179 |
aViewFilter, aFlags );
|
|
180 |
CleanupStack::Pop(); // result
|
|
181 |
}
|
|
182 |
else if ( aViewType == EVPbkGroupsView )
|
|
183 |
{
|
|
184 |
const MVPbkFieldTypeList* sortOrder = NULL;
|
|
185 |
|
|
186 |
// Acquire group sort order
|
|
187 |
RImplInfoPtrArray implementations;
|
|
188 |
REComSession::ListImplementationsL
|
|
189 |
( TUid::Uid( KVPbkSortOrderAcquirerInterfaceUID ), implementations );
|
|
190 |
CleanupStack::PushL( TCleanupItem
|
|
191 |
( CleanupResetAndDestroy, &implementations ) );
|
|
192 |
|
|
193 |
TBool found = EFalse;
|
|
194 |
const TInt count = implementations.Count();
|
|
195 |
for ( TInt i = count - 1; i >= 0 && !found ; --i )
|
|
196 |
{
|
|
197 |
CImplementationInformation* implInfo = implementations[i];
|
|
198 |
|
|
199 |
if ( implInfo->DisplayName().
|
|
200 |
CompareC( KGroupSortOrderDisplayName ) == 0 )
|
|
201 |
{
|
|
202 |
TUid implUid = implInfo->ImplementationUid();
|
|
203 |
|
|
204 |
CVPbkSortOrderAcquirer::TSortOrderAcquirerParam param
|
|
205 |
( iContactManager.FieldTypes() );
|
|
206 |
|
|
207 |
delete iSortOrderAcquirer;
|
|
208 |
iSortOrderAcquirer = NULL;
|
|
209 |
iSortOrderAcquirer = CVPbkSortOrderAcquirer::NewL
|
|
210 |
( implUid, param );
|
|
211 |
sortOrder = &iSortOrderAcquirer->SortOrder();
|
|
212 |
found = ETrue;
|
|
213 |
}
|
|
214 |
|
|
215 |
}
|
|
216 |
CleanupStack::PopAndDestroy(); // implementations
|
|
217 |
|
|
218 |
result = viewBuilder->CreateGroupViewForStoresLC
|
|
219 |
( aStoreUris, *this, *sortOrder,
|
|
220 |
aViewFilter, aFlags );
|
|
221 |
|
|
222 |
CleanupStack::Pop(); // result
|
|
223 |
}
|
|
224 |
|
|
225 |
CleanupStack::PopAndDestroy(); // viewBuilder
|
|
226 |
|
|
227 |
return result;
|
|
228 |
}
|
|
229 |
|
|
230 |
// --------------------------------------------------------------------------
|
|
231 |
// CPbk2ServerAppStoreManager::RemoveReadOnlyStoreUris
|
|
232 |
// --------------------------------------------------------------------------
|
|
233 |
//
|
|
234 |
void CPbk2ServerAppStoreManager::RemoveReadOnlyStoreUris
|
|
235 |
( CVPbkContactStoreUriArray& aStoreUriArray,
|
|
236 |
CPbk2StorePropertyArray& aStoreProperties ) const
|
|
237 |
{
|
|
238 |
// Browse the list backwards
|
|
239 |
for ( TInt i( aStoreUriArray.Count()-1 ); i >= 0; --i )
|
|
240 |
{
|
|
241 |
const CPbk2StoreProperty* storeProperty =
|
|
242 |
aStoreProperties.FindProperty( aStoreUriArray[i] );
|
|
243 |
|
|
244 |
if ( storeProperty && !( storeProperty->Flags() & KPbk2DefaultSavingStorageItem ) )
|
|
245 |
{
|
|
246 |
// Remove read only URI from the array
|
|
247 |
aStoreUriArray.Remove( aStoreUriArray[i] );
|
|
248 |
}
|
|
249 |
}
|
|
250 |
}
|
|
251 |
|
|
252 |
// --------------------------------------------------------------------------
|
|
253 |
// CPbk2ServerAppStoreManager::IsContactIncludedInCurrentConfigurationL
|
|
254 |
// --------------------------------------------------------------------------
|
|
255 |
//
|
|
256 |
TBool CPbk2ServerAppStoreManager::IsContactIncludedInCurrentConfigurationL
|
|
257 |
( const MVPbkStoreContact& aContact,
|
|
258 |
const CPbk2StoreConfiguration& aStoreConfiguration ) const
|
|
259 |
{
|
|
260 |
TBool result = EFalse;
|
|
261 |
|
|
262 |
TVPbkContactStoreUriPtr contactUri =
|
|
263 |
aContact.ParentStore().StoreProperties().Uri();
|
|
264 |
|
|
265 |
CVPbkContactStoreUriArray* currentConfig =
|
|
266 |
aStoreConfiguration.CurrentConfigurationL();
|
|
267 |
CleanupStack::PushL( currentConfig );
|
|
268 |
|
|
269 |
if ( currentConfig->IsIncluded( contactUri ) )
|
|
270 |
{
|
|
271 |
result = ETrue;
|
|
272 |
}
|
|
273 |
|
|
274 |
CleanupStack::PopAndDestroy( currentConfig );
|
|
275 |
|
|
276 |
return result;
|
|
277 |
}
|
|
278 |
|
|
279 |
// --------------------------------------------------------------------------
|
|
280 |
// CPbk2ServerAppStoreManager::ContactsAvailableL
|
|
281 |
// --------------------------------------------------------------------------
|
|
282 |
//
|
|
283 |
TBool CPbk2ServerAppStoreManager::ContactsAvailableL
|
|
284 |
( const MVPbkContactLinkArray& aContactLinks ) const
|
|
285 |
{
|
|
286 |
TBool ret = ETrue;
|
|
287 |
|
|
288 |
CVPbkContactStoreUriArray* validStores = CurrentlyValidStoresL();
|
|
289 |
|
|
290 |
for ( TInt i = 0; i < aContactLinks.Count(); ++ i )
|
|
291 |
{
|
|
292 |
const MVPbkContactLink& link = aContactLinks.At( i );
|
|
293 |
if ( !validStores->IsIncluded
|
|
294 |
( link.ContactStore().StoreProperties().Uri() ) )
|
|
295 |
{
|
|
296 |
ret = EFalse;
|
|
297 |
break;
|
|
298 |
}
|
|
299 |
}
|
|
300 |
|
|
301 |
delete validStores;
|
|
302 |
return ret;
|
|
303 |
}
|
|
304 |
|
|
305 |
// --------------------------------------------------------------------------
|
|
306 |
// CPbk2ServerAppStoreManager::CurrentlyValidStoresL
|
|
307 |
// --------------------------------------------------------------------------
|
|
308 |
//
|
|
309 |
CVPbkContactStoreUriArray*
|
|
310 |
CPbk2ServerAppStoreManager::CurrentlyValidStoresL() const
|
|
311 |
{
|
|
312 |
CVPbkContactStoreUriArray* uris = CVPbkContactStoreUriArray::NewLC();
|
|
313 |
|
|
314 |
const TInt count = iOpenedStores.Count();
|
|
315 |
for ( TInt i = 0 ; i < count; ++i )
|
|
316 |
{
|
|
317 |
uris->AppendL( iOpenedStores[i]->StoreProperties().Uri() );
|
|
318 |
}
|
|
319 |
|
|
320 |
CleanupStack::Pop( uris );
|
|
321 |
return uris;
|
|
322 |
}
|
|
323 |
|
|
324 |
// --------------------------------------------------------------------------
|
|
325 |
// CPbk2ServerAppStoreManager::ContactViewReady
|
|
326 |
// --------------------------------------------------------------------------
|
|
327 |
//
|
|
328 |
void CPbk2ServerAppStoreManager::ContactViewReady
|
|
329 |
( MVPbkContactViewBase& /*aView*/ )
|
|
330 |
{
|
|
331 |
// Do nothing
|
|
332 |
}
|
|
333 |
|
|
334 |
// --------------------------------------------------------------------------
|
|
335 |
// CPbk2ServerAppStoreManager::ContactViewUnavailable
|
|
336 |
// --------------------------------------------------------------------------
|
|
337 |
//
|
|
338 |
void CPbk2ServerAppStoreManager::ContactViewUnavailable
|
|
339 |
( MVPbkContactViewBase& /*aView*/ )
|
|
340 |
{
|
|
341 |
// Do nothing
|
|
342 |
}
|
|
343 |
|
|
344 |
// --------------------------------------------------------------------------
|
|
345 |
// CPbk2ServerAppStoreManager::ContactAddedToView
|
|
346 |
// --------------------------------------------------------------------------
|
|
347 |
//
|
|
348 |
void CPbk2ServerAppStoreManager::ContactAddedToView
|
|
349 |
( MVPbkContactViewBase& /*aView*/, TInt /*aIndex*/,
|
|
350 |
const MVPbkContactLink& /*aContactLink*/ )
|
|
351 |
{
|
|
352 |
// Do nothing
|
|
353 |
}
|
|
354 |
|
|
355 |
// --------------------------------------------------------------------------
|
|
356 |
// CPbk2ServerAppStoreManager::ContactRemovedFromView
|
|
357 |
// --------------------------------------------------------------------------
|
|
358 |
//
|
|
359 |
void CPbk2ServerAppStoreManager::ContactRemovedFromView
|
|
360 |
( MVPbkContactViewBase& /*aView*/, TInt /*aIndex*/,
|
|
361 |
const MVPbkContactLink& /*aContactLink*/ )
|
|
362 |
{
|
|
363 |
// Do nothing
|
|
364 |
}
|
|
365 |
|
|
366 |
// --------------------------------------------------------------------------
|
|
367 |
// CPbk2ServerAppStoreManager::ContactViewError
|
|
368 |
// --------------------------------------------------------------------------
|
|
369 |
//
|
|
370 |
void CPbk2ServerAppStoreManager::ContactViewError
|
|
371 |
( MVPbkContactViewBase& /*aView*/, TInt /*aError*/,
|
|
372 |
TBool /*aErrorNotified*/ )
|
|
373 |
{
|
|
374 |
// Do nothing
|
|
375 |
}
|
|
376 |
|
|
377 |
// --------------------------------------------------------------------------
|
|
378 |
// CPbk2ServerAppStoreManager::StoreReady
|
|
379 |
// --------------------------------------------------------------------------
|
|
380 |
//
|
|
381 |
void CPbk2ServerAppStoreManager::StoreReady
|
|
382 |
( MVPbkContactStore& aContactStore )
|
|
383 |
{
|
|
384 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
385 |
("CPbk2ServerAppStoreManager::StoreReady(0x%x)"),
|
|
386 |
&aContactStore);
|
|
387 |
|
|
388 |
// Add the store to the open stores list
|
|
389 |
if ( iOpenedStores.Find( &aContactStore ) == KErrNotFound )
|
|
390 |
{
|
|
391 |
iOpenedStores.Append( &aContactStore );
|
|
392 |
}
|
|
393 |
}
|
|
394 |
|
|
395 |
// --------------------------------------------------------------------------
|
|
396 |
// CPbk2ServerAppStoreManager::StoreUnavailable
|
|
397 |
// --------------------------------------------------------------------------
|
|
398 |
//
|
|
399 |
void CPbk2ServerAppStoreManager::StoreUnavailable
|
|
400 |
( MVPbkContactStore& aContactStore, TInt aReason )
|
|
401 |
{
|
|
402 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
|
|
403 |
("CPbk2ServerAppStoreManager::StoreUnavailable(0x%x,%d)"),
|
|
404 |
&aContactStore, aReason);
|
|
405 |
|
|
406 |
// Remove the store from the open store list if it is there
|
|
407 |
const TInt index = iOpenedStores.Find( &aContactStore );
|
|
408 |
if ( index != KErrNotFound )
|
|
409 |
{
|
|
410 |
iOpenedStores.Remove( index );
|
|
411 |
}
|
|
412 |
}
|
|
413 |
|
|
414 |
// --------------------------------------------------------------------------
|
|
415 |
// CPbk2ServerAppStoreManager::HandleStoreEventL
|
|
416 |
// --------------------------------------------------------------------------
|
|
417 |
//
|
|
418 |
void CPbk2ServerAppStoreManager::HandleStoreEventL
|
|
419 |
( MVPbkContactStore& /*aContactStore*/,
|
|
420 |
TVPbkContactStoreEvent /*aEvent*/ )
|
|
421 |
{
|
|
422 |
// Do nothing
|
|
423 |
}
|
|
424 |
|
|
425 |
// End of File
|