|
1 /* |
|
2 * Copyright (c) 2002-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: Manager for presence-list handling |
|
15 * (Contact-list updater/ Attribute-list publisher ). |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "CCAPEngListObserver.h" |
|
23 #include "ChatDebugPrint.h" |
|
24 #include "CAPresenceDefinitions.h" |
|
25 #include "CAPresenceUtils.h" |
|
26 #include "CCAPresenceErrors.h" |
|
27 #include "CAPresenceConst.h" |
|
28 |
|
29 #include "CCAStorageManagerFactory.h" |
|
30 #include "MCAStoredContacts.h" |
|
31 #include "MCAStoredContact.h" |
|
32 #include "MCAContactList.h" |
|
33 #include "MCAPresenceUpdater.h" |
|
34 |
|
35 #include <CPengPresenceNotifier2.h> |
|
36 #include <CPEngContactListStore2.h> |
|
37 #include <MPEngContactList2.h> |
|
38 #include <MPEngContactListObserver2.h> |
|
39 #include <MPEngContactListProperties.h> |
|
40 #include <PEngWVPresenceAttributes2.h> |
|
41 #include <CPEngContactListNotifier2.h> |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CCAPEngListObserver::CCAPEngListObserver |
|
47 // C++ default constructor can NOT contain any code, that |
|
48 // might leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CCAPEngListObserver::CCAPEngListObserver( |
|
52 CPEngPresenceNotifier2& aAttributeNotifier, |
|
53 RArray<TUint32>& aHandledAttributes, |
|
54 MCAPresenceUpdater& aUpdater ) |
|
55 : iAttributeNotifier( aAttributeNotifier ), |
|
56 iAttributes( aHandledAttributes ), |
|
57 iPresenceUpdater( aUpdater ) |
|
58 { |
|
59 CHAT_DP_FUNC_ENTER( "CCAPEngListObserver" ); |
|
60 CHAT_DP_FUNC_DONE( "CCAPEngListObserver" ); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CCAPEngListObserver::ConstructL |
|
65 // Symbian 2nd phase constructor can leave. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CCAPEngListObserver::ConstructL( CPEngNWSessionSlotID2* aSessionSlotID ) |
|
69 { |
|
70 CHAT_DP_FUNC_ENTER( "ConstructL" ); |
|
71 |
|
72 iStoredContacts = CCAStorageManagerFactory::ContactListInterfaceL(); |
|
73 iActiveListId = KNullDesC().AllocL(); |
|
74 |
|
75 iPEngContactListNotifier = |
|
76 CPEngContactListNotifier2::NewL( *aSessionSlotID ); |
|
77 iPEngContactListNotifier->AddObserver( *this ); |
|
78 |
|
79 iContactListStore = CPEngContactListStore2::NewL( *aSessionSlotID ); |
|
80 |
|
81 CHAT_DP_FUNC_DONE( "ConstructL" ); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CCAPEngListObserver::NewL |
|
86 // Two-phased constructor. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 CCAPEngListObserver* CCAPEngListObserver::NewL( |
|
90 CPEngNWSessionSlotID2* aSessionSlotID, |
|
91 CPEngPresenceNotifier2& aAttributeNotifier, |
|
92 RArray<TUint32>& aHandledAttributes, |
|
93 MCAPresenceUpdater& aUpdater ) |
|
94 { |
|
95 CHAT_DP_FUNC_ENTER( "NewL" ); |
|
96 |
|
97 CCAPEngListObserver* self = new( ELeave ) CCAPEngListObserver( |
|
98 aAttributeNotifier, |
|
99 aHandledAttributes, |
|
100 aUpdater ); |
|
101 |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL( aSessionSlotID ); |
|
104 CleanupStack::Pop( self ); |
|
105 |
|
106 CHAT_DP_FUNC_DONE( "NewL" ); |
|
107 |
|
108 return self; |
|
109 } |
|
110 |
|
111 // Destructor |
|
112 CCAPEngListObserver::~CCAPEngListObserver() |
|
113 { |
|
114 CHAT_DP_FUNC_ENTER( "~CCAPEngListObserver" ); |
|
115 |
|
116 if ( iPEngContactListNotifier ) |
|
117 { |
|
118 iPEngContactListNotifier->Stop(); |
|
119 iPEngContactListNotifier->RemoveObserver( *this ); |
|
120 } |
|
121 |
|
122 delete iContactListStore; |
|
123 delete iPEngContactListNotifier; |
|
124 delete iActiveListId; |
|
125 |
|
126 CHAT_DP_FUNC_DONE( "~CCAPEngListObserver" ); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CCAPEngListObserver::SetActiveListIdL |
|
131 // Setter for active contact list identifier |
|
132 // (other items were commented in a header). |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CCAPEngListObserver::SetActiveListIdL( const TDesC& aListId ) |
|
136 { |
|
137 CHAT_DP_FUNC_ENTER( "SetActiveListId" ); |
|
138 |
|
139 HBufC* tmp = aListId.AllocL(); |
|
140 delete iActiveListId; |
|
141 iActiveListId = tmp; |
|
142 |
|
143 // restart notifier |
|
144 iPEngContactListNotifier->Stop(); |
|
145 iPEngContactListNotifier->Start( *iActiveListId ); |
|
146 |
|
147 // this method is needed as we might move the getter to here also |
|
148 |
|
149 CHAT_DP_FUNC_DONE( "SetActiveListId" ); |
|
150 } |
|
151 |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CCAPEngListObserver::SetListIdsL |
|
155 // (other items were commented in a header). |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void CCAPEngListObserver::SetListIds( const MDesCArray& aListIds ) |
|
159 { |
|
160 // restart notifier |
|
161 iPEngContactListNotifier->Stop(); |
|
162 iPEngContactListNotifier->Start( aListIds ); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CCAPEngListObserver::ClearListNotifier |
|
167 // (other items were commented in a header). |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 void CCAPEngListObserver::ClearListNotifier() |
|
171 { |
|
172 iPEngContactListNotifier->Stop(); |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CCAPEngListObserver::StartNotifier |
|
177 // (other items were commented in a header). |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CCAPEngListObserver::StartNotifier( const TDesC& aListId ) |
|
181 { |
|
182 iPEngContactListNotifier->Stop(); |
|
183 iPEngContactListNotifier->Start( aListId ); |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CCAPEngListObserver::AddL |
|
188 // (other items were commented in a header). |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CCAPEngListObserver::AddL( const TDesC& aListId ) |
|
192 { |
|
193 if ( iPEngContactListNotifier->IsActive() ) |
|
194 { |
|
195 TInt err = iPEngContactListNotifier->Add( aListId ); |
|
196 if ( err != KErrAlreadyExists ) |
|
197 { |
|
198 User::LeaveIfError( err ); |
|
199 } |
|
200 } |
|
201 else |
|
202 { |
|
203 User::LeaveIfError( iPEngContactListNotifier->Start( aListId ) ); |
|
204 } |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CCAPEngListObserver::Remove |
|
209 // (other items were commented in a header). |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CCAPEngListObserver::Remove( const TDesC& aListId ) |
|
213 { |
|
214 iPEngContactListNotifier->Remove( aListId ); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CCAPEngListObserver::HandleContactListChangeL |
|
219 // (other items were commented in a header). |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CCAPEngListObserver::HandleContactListChangeL( |
|
223 CPEngContactListNotifier2& /*aNotifier*/, |
|
224 const TDesC& aContactListName ) |
|
225 { |
|
226 CHAT_DP_FUNC_ENTER( "HandleContactListChangeL" ); |
|
227 |
|
228 MPEngContactList2& list = |
|
229 iContactListStore->ContactListL( aContactListName ); |
|
230 |
|
231 // fetch list id and display name |
|
232 MPEngContactListProperties& prop = list.ListProperties(); |
|
233 TPtrC id( aContactListName ); |
|
234 TPtrC name( KNullDesC ); |
|
235 prop.DisplayName( name ); |
|
236 CHAT_DP( D_CHAT_LIT( "**listchange: %S [%S]" ), &id, &name ); |
|
237 |
|
238 MCAContactList* storedList = iStoredContacts->FindContactList( id ); |
|
239 if ( storedList ) |
|
240 { |
|
241 // list found, update displayname if it's changed |
|
242 if ( name.Length() > 0 && |
|
243 storedList->DisplayName().Compare( name ) != 0 ) |
|
244 { |
|
245 storedList->SetDisplayNameL( name ); |
|
246 } |
|
247 } |
|
248 else |
|
249 { |
|
250 // list not found, nothing to update |
|
251 return; |
|
252 } |
|
253 |
|
254 // check removed contacts |
|
255 const MDesCArray& removed = list.RemovedContacts(); |
|
256 TInt removeCount( removed.MdcaCount() ); |
|
257 CHAT_DP( D_CHAT_LIT( "removed wvids count %d" ), removeCount ); |
|
258 for ( TInt i( 0 ); i < removeCount; ++i ) |
|
259 { |
|
260 TPtrC id( removed.MdcaPoint( i ) ); |
|
261 CHAT_DP( D_CHAT_LIT( "HandleContactListChangeL - removed id %S" ), &id ); |
|
262 iStoredContacts->RemoveContact( aContactListName, id ); |
|
263 |
|
264 // remove from attribute notifier |
|
265 iAttributeNotifier.Remove( id ); |
|
266 } |
|
267 |
|
268 // check added contacts |
|
269 const MDesCArray& added = list.AddedContacts(); |
|
270 TInt addCount( added.MdcaCount() ); |
|
271 |
|
272 CHAT_DP( D_CHAT_LIT( "added wvids count %d" ), addCount ); |
|
273 for ( TInt ii( 0 ); ii < addCount; ++ii ) |
|
274 { |
|
275 TInt i( list.FindContact( added.MdcaPoint( ii ) ) ); |
|
276 // might be already removed |
|
277 if ( i != KErrNotFound ) |
|
278 { |
|
279 const MPEngContactItem& contact = list.ContactItem( i ); |
|
280 TPtrC id( contact.Id() ); |
|
281 TPtrC nick( contact.NickName() ); |
|
282 CHAT_DP( D_CHAT_LIT( "HandleContactListChangeL - contact id %S, \ |
|
283 nick %S" ), &id, &nick ); |
|
284 |
|
285 // add to attribute notifier |
|
286 TInt err = iAttributeNotifier.Add( id, iAttributes.Array() ); |
|
287 |
|
288 // updates existing contact or creates new |
|
289 iStoredContacts->CreateContactL( aContactListName, nick, id ); |
|
290 // make sure to update the presence |
|
291 iPresenceUpdater.UpdatePresenceL( id ); |
|
292 |
|
293 // leave with error. |
|
294 // Ignore inactive notifier (manual refresh mode) |
|
295 User::LeaveIfError( err == KErrNotReady ? KErrNone : err ); |
|
296 } |
|
297 } |
|
298 |
|
299 CHAT_DP_FUNC_DONE( "HandleContactListChangeL" ); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CCAPEngListObserver::HandleContactListError |
|
304 // (other items were commented in a header). |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 void CCAPEngListObserver::HandleContactListError( TInt aError, |
|
308 CPEngContactListNotifier2& /*aNotifier*/ ) |
|
309 { |
|
310 // ignored |
|
311 CHAT_DP_FUNC_ENTER( "HandleContactListNotifyError" ); |
|
312 |
|
313 // but print some debug information |
|
314 CHAT_DP( D_CHAT_LIT( "CCAPEngListObserver::HandleContactListNotifyError - \ |
|
315 Got error %d" ), aError ); |
|
316 |
|
317 CHAT_DP_FUNC_DONE( "HandleContactListNotifyError" ); |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CCAPEngListObserver::SkipStorageRemoval |
|
322 // (other items were commented in a header). |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 void CCAPEngListObserver::SkipStorageRemoval() |
|
326 { |
|
327 iSkipRemoval = ETrue; |
|
328 } |
|
329 |
|
330 // End of File |