|
1 /* |
|
2 * Copyright (c) 2005 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: Contact lists manager |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <e32std.h> |
|
20 |
|
21 #include "CPEngContactListManager.h" |
|
22 |
|
23 #include "CPEngContactListModBase.h" |
|
24 #include "CPEngContactListSettings.h" |
|
25 #include "CPEngSessionSlotId.h" |
|
26 |
|
27 #include "MPEngListLibFactory.h" |
|
28 |
|
29 #include "PresenceDebugPrint.h" |
|
30 |
|
31 #include "PEngContactIdsTools.h" |
|
32 |
|
33 #include "MPEngStorageManager.h" |
|
34 |
|
35 |
|
36 //Default granurality for list of lists |
|
37 const TInt KListOfListsGranurality = 3; |
|
38 |
|
39 |
|
40 // ============================ MEMBER FUNCTIONS =============================== |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CPEngContactListManager::CPEngContactListManager() |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CPEngContactListManager::CPEngContactListManager( MPEngListLibFactory& aFactory ) |
|
47 : CPEngContactListManagerBase( aFactory ), |
|
48 iAllLists( KListOfListsGranurality ), |
|
49 iSynchronizedLists( KListOfListsGranurality ) |
|
50 { |
|
51 } |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CPEngContactListManager::ConstructL() |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void CPEngContactListManager::ConstructL( const CPEngSessionSlotId& aSessionSlot ) |
|
59 { |
|
60 CPEngContactListManagerBase::ConstructL( aSessionSlot ); |
|
61 HandleSettingsUpdateL(); |
|
62 } |
|
63 |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CPEngContactListManager::NewL() |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CPEngContactListManager* CPEngContactListManager::NewL( |
|
70 MPEngListLibFactory& aFactory, |
|
71 const CPEngSessionSlotId& aSessionSlot ) |
|
72 { |
|
73 CPEngContactListManager* self = NewLC( aFactory, aSessionSlot ); |
|
74 CleanupStack::Pop(); //self |
|
75 return self; |
|
76 } |
|
77 |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CPEngContactListManager::NewLC |
|
81 // Two-phased constructor. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CPEngContactListManager* CPEngContactListManager::NewLC( |
|
85 MPEngListLibFactory& aFactory, |
|
86 const CPEngSessionSlotId& aSessionSlot ) |
|
87 { |
|
88 CPEngContactListManager* self = |
|
89 new ( ELeave ) CPEngContactListManager( aFactory ); |
|
90 |
|
91 CleanupClosePushL( *self ); |
|
92 self->ConstructL( aSessionSlot ); |
|
93 return self; |
|
94 } |
|
95 |
|
96 |
|
97 // Destructor |
|
98 CPEngContactListManager::~CPEngContactListManager() |
|
99 { |
|
100 iAllLists.Reset(); |
|
101 iSynchronizedLists.Reset(); |
|
102 } |
|
103 |
|
104 |
|
105 |
|
106 // ============================================================================= |
|
107 // ===============Function from MPEngContactListManager ======================= |
|
108 // ============================================================================= |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CPEngContactListManager::Close() |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CPEngContactListManager::Close() |
|
115 { |
|
116 iAccessCount--; |
|
117 if ( iAccessCount == 0 ) |
|
118 { |
|
119 iFactory.RemoveCntListManager( this ); |
|
120 delete this; |
|
121 } |
|
122 } |
|
123 |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CPEngContactListManager::ContactListL() |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 MPEngContactListAdvance& CPEngContactListManager::ContactListL( |
|
130 const TDesC& aContactList ) |
|
131 { |
|
132 return LoadContactListModelL( aContactList, EFalse, EFalse ); |
|
133 } |
|
134 |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CPEngContactListManager::PEngActiveContactLists() |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 const MDesCArray& CPEngContactListManager::AllContactListsL() const |
|
141 { |
|
142 return iAllLists; |
|
143 } |
|
144 |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CPEngContactListManager::PEngActiveContactLists() |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 const MDesCArray& CPEngContactListManager::SynchronizedContactLists() const |
|
151 { |
|
152 return iSynchronizedLists; |
|
153 } |
|
154 |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CPEngContactListManager::ContactListSettingsL() |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 MPEngContactListProperties& CPEngContactListManager::ContactListSettingsL( |
|
161 const TDesC& aContacList ) |
|
162 { |
|
163 CPEngContactListSettings* settings = ContactListSettingsOrNull( aContacList ); |
|
164 if ( !settings ) |
|
165 { |
|
166 User::Leave( KErrNotFound ); |
|
167 } |
|
168 |
|
169 return *settings; |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CPEngContactListManager::SetAsDefaultCntListL() |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void CPEngContactListManager::SetAsDefaultCntListL( |
|
177 const TDesC& aContactList ) |
|
178 { |
|
179 // find contact list and set it as new default contact list |
|
180 MPEngContactListProperties& settings = ContactListSettingsL( aContactList ); |
|
181 |
|
182 |
|
183 // is it already default contact list |
|
184 if ( settings.IsDefault() ) |
|
185 { |
|
186 settings.DeletePropertyL( KPEngNewDefaultContactList, |
|
187 KPEngCntLstPropertyNativeCached ); |
|
188 return; |
|
189 } |
|
190 |
|
191 |
|
192 // update settings |
|
193 settings.SetPropertyL( KPEngNewDefaultContactList, |
|
194 KPEngCntLstPropertyNativeCached, |
|
195 ETrue ); |
|
196 |
|
197 settings.SetPropertyL( KPEngPropertiesUpdateNeeded, |
|
198 KPEngCntLstPropertyNativeCached, |
|
199 ETrue ); |
|
200 |
|
201 // update settings in the current default contact list |
|
202 MPEngContactListProperties* defaultCntList = DefaultCntListSettingsOrNull(); |
|
203 if ( defaultCntList ) |
|
204 { |
|
205 defaultCntList->SetPropertyL( KPEngNewDefaultContactList, |
|
206 KPEngCntLstPropertyNativeCached, |
|
207 KErrCancel ); |
|
208 } |
|
209 } |
|
210 |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CPEngContactListManager::CreateContactListL() |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 MPEngContactListProperties& CPEngContactListManager::CreateContactListL( |
|
217 const TDesC& aContactList, |
|
218 TPEngContactListBaseSettings& aBaseSettings ) |
|
219 { |
|
220 // check if such a list not exist already |
|
221 if ( ContactListSettingsOrNull( aContactList ) ) |
|
222 { |
|
223 User::Leave( KErrAlreadyExists ); |
|
224 } |
|
225 |
|
226 |
|
227 // add new contact list settings |
|
228 CPEngContactListSettings* newList = CPEngContactListSettings::NewLC( |
|
229 aContactList, |
|
230 aBaseSettings, |
|
231 *this ); |
|
232 if ( aBaseSettings.iContactListNameAutoUpdate ) |
|
233 { |
|
234 // get user name |
|
235 TChar domainSeparator( '@' ); |
|
236 TInt offset( iSessionId->UserId().LocateF( domainSeparator ) ); |
|
237 TPtrC userName( KErrNotFound == offset ? iSessionId->UserId() |
|
238 : iSessionId->UserId().Left( offset ) ); |
|
239 |
|
240 newList->UpdateListServerNameL( userName, iUserDomain ); |
|
241 } |
|
242 |
|
243 |
|
244 InsertContactListSettingsL( *newList ); |
|
245 CleanupStack::Pop(); // newList |
|
246 |
|
247 // update array of lists and store settings |
|
248 HandleSettingsUpdateL(); |
|
249 StoreSettingsL(); |
|
250 |
|
251 return *newList; |
|
252 } |
|
253 |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CPEngContactListManager::DeleteContactListL() |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CPEngContactListManager::DeleteContactListL( const TDesC& aContactList ) |
|
260 { |
|
261 if ( ContactListModelOrNull( aContactList ) ) |
|
262 { |
|
263 User::Leave( KErrInUse ); |
|
264 } |
|
265 |
|
266 |
|
267 CPEngContactListSettings* cntList = ContactListSettingsOrNull( aContactList ); |
|
268 if ( !cntList ) |
|
269 { |
|
270 User::Leave( KErrNotFound ); |
|
271 } |
|
272 |
|
273 |
|
274 cntList->SetPropertyL( KPEngContactListDeleteNeeded, |
|
275 KPEngCntLstPropertyNativeCached, |
|
276 ETrue ); |
|
277 } |
|
278 |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CPEngContactListManager::ChangeContactListTypeL() |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 void CPEngContactListManager::ChangeContactListTypeL( |
|
285 const TDesC& aContactList, |
|
286 TPEngContactListType aContactListType ) |
|
287 { |
|
288 // find contact list settings |
|
289 CPEngContactListSettings* settings = ContactListSettingsOrNull( aContactList ); |
|
290 if ( !settings ) |
|
291 { |
|
292 User::Leave( KErrNotFound ); |
|
293 } |
|
294 |
|
295 if ( settings->BaseSettings().iContactListType == aContactListType ) |
|
296 { |
|
297 // type is same, nothing to do |
|
298 return; |
|
299 } |
|
300 |
|
301 // load model |
|
302 CPEngContactListModBase* model = &LoadContactListModelL( aContactList, |
|
303 EFalse, |
|
304 ETrue ); |
|
305 // update storage type of the model |
|
306 model->ChangeStorageTypeL( CPEngContactListModBase::StoreTypeForListType( aContactListType ) ); |
|
307 settings->UpdateListTypeL( aContactListType ); |
|
308 } |
|
309 |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CPEngContactListManager::ReleaseCntListModel() |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 void CPEngContactListManager::ReleaseCntListModel( const TDesC& aContactList ) |
|
316 { |
|
317 CPEngContactListModBase* model = ContactListModelOrNull( aContactList ); |
|
318 if ( model ) |
|
319 { |
|
320 model->Close(); |
|
321 } |
|
322 } |
|
323 |
|
324 |
|
325 |
|
326 // ============================================================================= |
|
327 // =============== from CPEngContactListManagerBase ============================ |
|
328 // ============================================================================= |
|
329 |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // CPEngContactListManager::HandleSettingsUpdateL() |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 void CPEngContactListManager::HandleSettingsUpdateL( void ) |
|
336 { |
|
337 CPEngContactListManagerBase::HandleSettingsUpdateL(); |
|
338 |
|
339 |
|
340 iAllLists.Reset(); |
|
341 iSynchronizedLists.Reset(); |
|
342 |
|
343 |
|
344 TInt count ( iContactListSettings.Count() ); |
|
345 for ( TInt x( 0 ) ; x < count ; x++ ) |
|
346 { |
|
347 CPEngContactListSettings* listSettings = iContactListSettings[ x ]; |
|
348 |
|
349 iAllLists.AppendL( listSettings->Name() ); |
|
350 |
|
351 if ( listSettings->Synchronized() ) |
|
352 { |
|
353 iSynchronizedLists.AppendL( listSettings->Name() ); |
|
354 } |
|
355 } |
|
356 |
|
357 |
|
358 // look for models of the contact lists which has been deleted and remove them |
|
359 count = iContactLists.Count() - 1; |
|
360 for ( ; count >= 0 ; --count ) |
|
361 { |
|
362 if ( !( & ( iContactLists[ count ]->Settings() ) ) ) |
|
363 { |
|
364 // intance removes itself from array in its destructor |
|
365 iContactLists[ count ]->Close(); |
|
366 } |
|
367 } |
|
368 } |
|
369 |
|
370 // End of File |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |