|
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: Implementation of contact data container |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CCAContact.h" |
|
22 #include "CCAStorage.h" |
|
23 #include "TCAStoragePanics.h" |
|
24 #include "MCAStoredContactsObserver.h" |
|
25 #include "MCAStorageInfo.h" |
|
26 #include "TStorageManagerGlobals.h" |
|
27 #include "ChatDebugPrint.h" |
|
28 #include "CCAStorageDefs.h" |
|
29 #include "CAUtils.h" |
|
30 |
|
31 #include <e32base.h> |
|
32 #include <e32std.h> |
|
33 #include <e32def.h> |
|
34 #include <s32strm.h> |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CCAContact::CCAContact |
|
40 // C++ default constructor can NOT contain any code, that |
|
41 // might leave. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CCAContact::CCAContact( MCAStoredContactsObserver* aObserver, |
|
45 MCAStorageInfo* aVariation ) : |
|
46 iObserver( aObserver ), iVariation( aVariation ) |
|
47 { |
|
48 iPresenceStatus = TStorageManagerGlobals::EUnknown; |
|
49 iClientType = TStorageManagerGlobals::EUnknownClient; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CCAContact::ConstructL |
|
54 // Symbian 2nd phase constructor can leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CCAContact::ConstructL() |
|
58 { |
|
59 // creating empty user id to making sure that we always have some |
|
60 // initial "value", even though it is empty. |
|
61 // User id is necesssary information |
|
62 // for contact. |
|
63 iUserId = HBufC::NewL( 1 ); |
|
64 |
|
65 // same for nickname |
|
66 iNickname = HBufC::NewL( 1 ); |
|
67 |
|
68 // same for alias |
|
69 iAlias = HBufC::NewL( 1 ); |
|
70 |
|
71 UpdateIdentification(); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CCAContact::NewL |
|
76 // Two-phased constructor. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CCAContact* CCAContact::NewL( MCAStoredContactsObserver* aObserver, |
|
80 MCAStorageInfo* aVariation ) |
|
81 { |
|
82 CCAContact* self = new( ELeave ) CCAContact( aObserver, aVariation ); |
|
83 |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL(); |
|
86 CleanupStack::Pop( self ); |
|
87 |
|
88 return self; |
|
89 } |
|
90 |
|
91 |
|
92 // Destructor |
|
93 CCAContact::~CCAContact() |
|
94 { |
|
95 delete iUserId; |
|
96 delete iNickname; |
|
97 delete iAlias; |
|
98 delete iStatusText; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CCAContact::UserId |
|
103 // From MCAStoredContact |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 const TDesC& CCAContact::UserId() const |
|
107 { |
|
108 __ASSERT_ALWAYS( iUserId, Panic( ENoSuitableUserId ) ); |
|
109 return *( iUserId ); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CCAContact::Nickname |
|
114 // From MCAStoredContact |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 const TDesC& CCAContact::Nickname() const |
|
118 { |
|
119 if ( iNickname ) |
|
120 { |
|
121 return *iNickname; |
|
122 } |
|
123 return KNullDesC; |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CCAContact::Alias |
|
128 // From MCAStoredContact |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 const TDesC& CCAContact::Alias() const |
|
132 { |
|
133 if ( iAlias ) |
|
134 { |
|
135 return *iAlias; |
|
136 } |
|
137 return KNullDesC; |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CCAContact::Identification |
|
142 // From MCAStoredContact |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 const TDesC& CCAContact::Identification() const |
|
146 { |
|
147 return iIdentification; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CCAContact::OnlineStatus |
|
152 // From MCAStoredContact |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TStorageManagerGlobals::TPresenceStatus CCAContact::OnlineStatus() const |
|
156 { |
|
157 return iPresenceStatus; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CCAContact::IsBlocked |
|
162 // From MCAStoredContact |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 TBool CCAContact::IsBlocked() const |
|
166 { |
|
167 return iIsBlocked; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CCAContact::IsWatched |
|
172 // From MCAStoredContact |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 TBool CCAContact::IsWatched() const |
|
176 { |
|
177 return iWatcherActive; |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CCAContact::ClientType |
|
182 // From MCAStoredContact |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 TStorageManagerGlobals::TClientType CCAContact::ClientType() const |
|
186 { |
|
187 return iClientType; |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CCAContact::SetClientType |
|
192 // From MCAStoredContact |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CCAContact::SetClientType( TStorageManagerGlobals::TClientType aType ) |
|
196 { |
|
197 if ( iClientType != aType ) |
|
198 { |
|
199 // state different, has changed |
|
200 iIsChanged |= 1; |
|
201 } |
|
202 |
|
203 iClientType = aType; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CCAContact::SetOnlineStatus |
|
208 // From MCAStoredContact |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CCAContact::SetOnlineStatus( |
|
212 TStorageManagerGlobals::TPresenceStatus aOnlineStatus ) |
|
213 { |
|
214 if ( iPresenceStatus != aOnlineStatus ) |
|
215 { |
|
216 // state different, has changed |
|
217 iIsChanged |= 1; |
|
218 } |
|
219 |
|
220 iPresenceStatus = aOnlineStatus; |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CCAContact::SetBlocked |
|
225 // From MCAStoredContact |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 void CCAContact::SetBlocked( TBool aBlocked ) |
|
229 { |
|
230 if ( iIsBlocked != aBlocked ) |
|
231 { |
|
232 // state different, has changed |
|
233 iIsChanged |= 1; |
|
234 } |
|
235 |
|
236 iIsBlocked = aBlocked; |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CCAContact::SetWatched |
|
241 // From MCAStoredContact |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 void CCAContact::SetWatched( TBool aWatched ) |
|
245 { |
|
246 if ( iWatcherActive != aWatched ) |
|
247 { |
|
248 // state different, has changed |
|
249 iIsChanged |= 1; |
|
250 } |
|
251 |
|
252 iWatcherActive = aWatched; |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CCAContact::SetPendingMessages |
|
257 // From MCAExtendedStoredContact |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 void CCAContact::SetPendingMessages( TInt aAmount ) |
|
261 { |
|
262 if ( iPendingMessages != aAmount ) |
|
263 { |
|
264 // state different, has changed |
|
265 iIsChanged |= 1; |
|
266 } |
|
267 |
|
268 iPendingMessages = aAmount; |
|
269 } |
|
270 |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CCAContact::SignalChanges |
|
274 // From MCAStoredContact |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 void CCAContact::SignalChanges() |
|
278 { |
|
279 TBool wasChanged( 0 != iIsChanged ); |
|
280 iIsChanged = 0; |
|
281 |
|
282 if ( wasChanged ) |
|
283 { |
|
284 // The observer shall decide whether to pass the information onward. |
|
285 iObserver->HandleChange( NULL, this, |
|
286 TStorageManagerGlobals::EStorageEventPostChange, iUserIdChanged ); |
|
287 } |
|
288 |
|
289 iUserIdChanged = EFalse; |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CCAContact::Selected |
|
294 // From MCAStoredContact |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 TBool CCAContact::Selected() const |
|
298 { |
|
299 return iSelected; |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CCAContact::SetSelected |
|
304 // From MCAStoredContact |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 void CCAContact::SetSelected( TBool aSelected ) |
|
308 { |
|
309 iSelected = aSelected; |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CCAContact::SetSelected |
|
314 // From MCAStoredContact |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 TInt CCAContact::PendingMessages() const |
|
318 { |
|
319 return iPendingMessages; |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // CCAContact::StatusText |
|
324 // From MCAStoredContact |
|
325 // ----------------------------------------------------------------------------- |
|
326 // |
|
327 const TDesC& CCAContact::StatusText() const |
|
328 { |
|
329 if ( iStatusText ) |
|
330 { |
|
331 return *iStatusText; |
|
332 } |
|
333 return KNullDesC; |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CCAContact::SetStatusTextL |
|
338 // From MCAStoredContact |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void CCAContact::SetStatusTextL( const TDesC& aStatusText ) |
|
342 { |
|
343 HBufC* tmp = aStatusText.AllocL(); |
|
344 delete iStatusText; |
|
345 iStatusText = tmp; |
|
346 } |
|
347 |
|
348 // ----------------------------------------------------------------------------- |
|
349 // CCAContact::GetPropertyL |
|
350 // From MCAStoredContact |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 HBufC* CCAContact::PropertyL( |
|
354 TStorageManagerGlobals::TCAStorageProperty aProperty ) |
|
355 { |
|
356 switch ( aProperty ) |
|
357 { |
|
358 case TStorageManagerGlobals::EStoragePropNickname : |
|
359 { |
|
360 return iNickname->AllocL(); |
|
361 // break; // RVCT |
|
362 } |
|
363 case TStorageManagerGlobals::EStoragePropAlias : |
|
364 { |
|
365 return iAlias->AllocL(); |
|
366 // break; // RVCT |
|
367 } |
|
368 default : |
|
369 { |
|
370 return NULL; |
|
371 } |
|
372 } |
|
373 } |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // CCAContact::GetPropertyL |
|
377 // From MCAStoredContact |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 void CCAContact::SetPropertyL( |
|
381 TStorageManagerGlobals::TCAStorageProperty aProperty, |
|
382 const TDesC& aData ) |
|
383 { |
|
384 switch ( aProperty ) |
|
385 { |
|
386 case TStorageManagerGlobals::EStoragePropNickname : |
|
387 { |
|
388 // set nickname |
|
389 HBufC* tmp = aData.AllocL(); |
|
390 delete iNickname; |
|
391 iNickname = tmp; |
|
392 |
|
393 UpdateIdentification(); |
|
394 break; |
|
395 } |
|
396 case TStorageManagerGlobals::EStoragePropAlias : |
|
397 { |
|
398 HBufC* tmp = aData.AllocL(); |
|
399 delete iAlias; |
|
400 iAlias = tmp; |
|
401 |
|
402 UpdateIdentification(); |
|
403 break; |
|
404 } |
|
405 case TStorageManagerGlobals::EStoragePropUserId: |
|
406 { |
|
407 SetUserIdL( aData ); |
|
408 break; |
|
409 } |
|
410 default : |
|
411 { |
|
412 // no such property |
|
413 User::Leave( KErrArgument ); |
|
414 break; |
|
415 } |
|
416 } |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CCAContact::UpdateIdentification |
|
421 // Update identification of contact |
|
422 // ----------------------------------------------------------------------------- |
|
423 // |
|
424 void CCAContact::UpdateIdentification() |
|
425 { |
|
426 iIsChanged |= 1; |
|
427 |
|
428 if ( iVariation && iVariation->ShowNickname() |
|
429 && ( iNickname->Length() > 0 ) ) |
|
430 { |
|
431 // use nickname as identification |
|
432 iIdentification.Set( *iNickname ); |
|
433 return; |
|
434 } |
|
435 |
|
436 // no nickname |
|
437 if ( iAlias->Length() > 0 ) |
|
438 { |
|
439 // use alias as identification from now on |
|
440 iIdentification.Set( *iAlias ); |
|
441 return; |
|
442 } |
|
443 |
|
444 // otherwise always fallback to userid |
|
445 iIdentification.Set( CAUtils::DisplayId( *iUserId ) ); |
|
446 } |
|
447 |
|
448 // ----------------------------------------------------------------------------- |
|
449 // CCAContact::SetUserIdL |
|
450 // From MCAExtendedStoredContact |
|
451 // ----------------------------------------------------------------------------- |
|
452 // |
|
453 void CCAContact::SetUserIdL( const TDesC& aUserId ) |
|
454 { |
|
455 HBufC* tempUserId = aUserId.AllocL(); |
|
456 delete iUserId; |
|
457 iUserId = tempUserId; |
|
458 iUserIdChanged = ETrue; |
|
459 |
|
460 UpdateIdentification(); |
|
461 } |
|
462 |
|
463 // ----------------------------------------------------------------------------- |
|
464 // CCAContact::SetNickname |
|
465 // From MCAExtendedStoredContact |
|
466 // ----------------------------------------------------------------------------- |
|
467 // |
|
468 void CCAContact::SetNicknameL( const TDesC& aNickname ) |
|
469 { |
|
470 HBufC* tempNickname = aNickname.AllocL(); |
|
471 delete iNickname; |
|
472 iNickname = tempNickname; |
|
473 |
|
474 UpdateIdentification(); |
|
475 } |
|
476 |
|
477 // ----------------------------------------------------------------------------- |
|
478 // CCAContact::SetAliasL |
|
479 // From MCAExtendedStoredContact |
|
480 // ----------------------------------------------------------------------------- |
|
481 // |
|
482 void CCAContact::SetAliasL( const TDesC& aAlias ) |
|
483 { |
|
484 HBufC* tempAlias = aAlias.AllocL(); |
|
485 delete iAlias; |
|
486 iAlias = tempAlias; |
|
487 |
|
488 UpdateIdentification(); |
|
489 } |
|
490 |
|
491 |
|
492 // End of File |