|
1 /* |
|
2 * Copyright (c) 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 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "cmscontact.h" |
|
20 #include "cmssession.h" |
|
21 #include "cmscontactfield.h" |
|
22 #include "cmscontactfieldinfo.h" |
|
23 #include "cmscommondefines.h" |
|
24 #include "cmscontactnotifier.h" |
|
25 |
|
26 // ---------------------------------------------------- |
|
27 // RCmsContact::RCmsContact |
|
28 // |
|
29 // ---------------------------------------------------- |
|
30 // |
|
31 EXPORT_C RCmsContact::RCmsContact() : iContactIdentifierPtr( NULL, 0 ) |
|
32 { |
|
33 } |
|
34 |
|
35 // ---------------------------------------------------- |
|
36 // RCmsContact::~RCmsContact |
|
37 // |
|
38 // ---------------------------------------------------- |
|
39 // |
|
40 EXPORT_C RCmsContact::~RCmsContact() |
|
41 { |
|
42 iNotifiers.ResetAndDestroy(); |
|
43 } |
|
44 |
|
45 // ---------------------------------------------------- |
|
46 // RCmsContact::Open |
|
47 // |
|
48 // ---------------------------------------------------- |
|
49 // |
|
50 EXPORT_C TInt RCmsContact::Open( RCmsSession& aSession, |
|
51 TInt32 aContactId ) |
|
52 { |
|
53 #ifdef _DEBUG |
|
54 RCmsSession::WriteToLog( _L8( "RCmsContact::Open( ID )" ) ); |
|
55 RCmsSession::WriteToLog( _L8( " Contact ID: %d" ), aContactId ); |
|
56 #endif |
|
57 return CreateSubSession( aSession, ECmsOpenID, TIpcArgs( aContactId ) ); |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------- |
|
61 // RCmsContact::Open |
|
62 // |
|
63 // ---------------------------------------------------- |
|
64 // |
|
65 EXPORT_C TInt RCmsContact::Open( RCmsSession& aSession, |
|
66 const TDesC8& aPackedLink ) |
|
67 { |
|
68 #ifdef _DEBUG |
|
69 RCmsSession::WriteToLog( _L8( "RCmsContact::Open( LINK )" ) ); |
|
70 #endif |
|
71 return CreateSubSession( aSession, ECmsOpenLink, TIpcArgs( &aPackedLink ) ); |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------- |
|
75 // RCmsContact::Open |
|
76 // |
|
77 // ---------------------------------------------------- |
|
78 // |
|
79 EXPORT_C TInt RCmsContact::Open( RCmsSession& aSession, |
|
80 const TDesC& aPhoneNbr ) |
|
81 { |
|
82 #ifdef _DEBUG |
|
83 HBufC8* phoneBuf = HBufC8::NewLC( aPhoneNbr.Length() ); |
|
84 phoneBuf->Des().Copy( aPhoneNbr ); |
|
85 TPtrC8 phoneDesc( phoneBuf->Des() ); |
|
86 RCmsSession::WriteToLog( _L8( "RCmsContact::Open( MSISDN )" ) ); |
|
87 RCmsSession::WriteToLog( _L8( " Phone number: %S" ), &phoneDesc ); |
|
88 CleanupStack::PopAndDestroy(); //phoneBuf |
|
89 #endif |
|
90 return CreateSubSession( aSession, ECmsOpenPhoneNbr, TIpcArgs( &aPhoneNbr ) ); |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------- |
|
94 // RCmsContact::FieldDataL |
|
95 // |
|
96 // ---------------------------------------------------- |
|
97 // |
|
98 EXPORT_C CCmsContactField* RCmsContact::FieldDataL( TRequestStatus& aStatus, |
|
99 CCmsContactFieldItem::TCmsContactField aFieldType ) |
|
100 { |
|
101 #ifdef _DEBUG |
|
102 RCmsSession::WriteToLog( _L8( "RCmsContact::FieldDataL( SINGLE ): %d" ), aFieldType ); |
|
103 #endif |
|
104 CCmsContactField* field = CCmsContactField::NewL( *this, aStatus, aFieldType ); |
|
105 SendMessage( ECmsFetchContactField, *field, aFieldType ); |
|
106 return field; |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------- |
|
110 // RCmsContact::EnabledFields |
|
111 // |
|
112 // ---------------------------------------------------- |
|
113 // |
|
114 EXPORT_C CCmsContactFieldInfo* RCmsContact::EnabledFieldsL( TRequestStatus& aStatus ) |
|
115 { |
|
116 #ifdef _DEBUG |
|
117 RCmsSession::WriteToLog( _L8( "RCmsContact::EnabledFieldsL()" ) ); |
|
118 #endif |
|
119 CCmsContactFieldInfo* info = CCmsContactFieldInfo::NewL( *this, aStatus ); |
|
120 TIpcArgs arguments( info->StreamDesc8() ); |
|
121 SendMessage( ECmsFetchEnabledFields, arguments, info->Activate() ); |
|
122 return info; |
|
123 } |
|
124 |
|
125 // ---------------------------------------------------- |
|
126 // RCmsContact::IsServiceAvailable |
|
127 // |
|
128 // ---------------------------------------------------- |
|
129 // |
|
130 EXPORT_C TInt RCmsContact::IsServiceAvailable( VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aServiceType ) const |
|
131 { |
|
132 #ifdef _DEBUG |
|
133 RCmsSession::WriteToLog( _L8( "RCmsContact::IsServiceAvailable() - Field: %d" ), aServiceType ); |
|
134 #endif |
|
135 if( VPbkFieldTypeSelectorFactory::EEmailEditorSelector == aServiceType ) |
|
136 { |
|
137 // Resolving email accounts is too slow -> |
|
138 // CCA show email item if email field is defined in contact |
|
139 return ETrue; |
|
140 } |
|
141 return SendReceive( ECmsFetchServiceAvailability, TIpcArgs( aServiceType ) ); |
|
142 } |
|
143 |
|
144 // ---------------------------------------------------- |
|
145 // RCmsContact::ContactStore |
|
146 // |
|
147 // ---------------------------------------------------- |
|
148 // |
|
149 EXPORT_C TCmsContactStore RCmsContact::ContactStore() const |
|
150 { |
|
151 #ifdef _DEBUG |
|
152 RCmsSession::WriteToLog( _L8( "RCmsContact::ContactStore()" ) ); |
|
153 #endif |
|
154 TInt result = SendReceive( ECmsFindParentStore, TIpcArgs() ); |
|
155 return ( TCmsContactStore )result; |
|
156 } |
|
157 |
|
158 // ---------------------------------------------------- |
|
159 // RCmsContact::FindExternalContact |
|
160 // |
|
161 // ---------------------------------------------------- |
|
162 // |
|
163 EXPORT_C void RCmsContact::FindExternalContact( TRequestStatus& aStatus ) const |
|
164 { |
|
165 #ifdef _DEBUG |
|
166 RCmsSession::WriteToLog( _L8( "RCmsContact::FindExternalStore()" ) ); |
|
167 #endif |
|
168 SendReceive( ECmsFindExternalContact, TIpcArgs(), aStatus ); |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------- |
|
172 // RCmsContact::GetContactIdentifierL |
|
173 // |
|
174 // ---------------------------------------------------- |
|
175 // |
|
176 EXPORT_C HBufC8* RCmsContact::GetContactIdentifierL() |
|
177 { |
|
178 #ifdef _DEBUG |
|
179 RCmsSession::WriteToLog( _L8( "RCmsContact::GetContactIdentifierL()" ) ); |
|
180 #endif |
|
181 |
|
182 HBufC8* identifierbuffer = HBufC8::NewL( KStreamBufferDefaultSizeText ); |
|
183 iContactIdentifierPtr.Set( identifierbuffer->Des() ); |
|
184 |
|
185 //Currently only MVPbkContactLinkArray is supported. |
|
186 SendReceive(ECmsFetchContactIdentifier, TIpcArgs(&iContactIdentifierPtr)); |
|
187 |
|
188 return identifierbuffer; |
|
189 } |
|
190 |
|
191 |
|
192 // ---------------------------------------------------- |
|
193 // RCmsContact::Cancel |
|
194 // |
|
195 // ---------------------------------------------------- |
|
196 // |
|
197 EXPORT_C void RCmsContact::Cancel( CCmsContactBase& aContactBase ) |
|
198 { |
|
199 #ifdef _DEBUG |
|
200 RCmsSession::WriteToLog( _L8( "RCmsContact::Cancel()" ) ); |
|
201 #endif |
|
202 aContactBase.Cancel(); |
|
203 Send(ECmsCancelOperation , TIpcArgs() ); |
|
204 } |
|
205 |
|
206 // ---------------------------------------------------- |
|
207 // RCmsContact::CancelExternalContactFind |
|
208 // |
|
209 // ---------------------------------------------------- |
|
210 // |
|
211 EXPORT_C void RCmsContact::CancelExternalContactFind() const |
|
212 { |
|
213 #ifdef _DEBUG |
|
214 RCmsSession::WriteToLog( _L8( "RCmsContact::CancelExternalContactFind()" ) ); |
|
215 #endif |
|
216 Send( ECmsCancelExternalContactFind, TIpcArgs() ); |
|
217 } |
|
218 |
|
219 // ---------------------------------------------------- |
|
220 // RCmsContact::Close |
|
221 // |
|
222 // ---------------------------------------------------- |
|
223 // |
|
224 EXPORT_C void RCmsContact::Close() |
|
225 { |
|
226 #ifdef _DEBUG |
|
227 RCmsSession::WriteToLog( _L8( "RCmsContact::Close()" ) ); |
|
228 #endif |
|
229 |
|
230 iNotifiers.ResetAndDestroy(); |
|
231 |
|
232 RSubSessionBase::CloseSubSession( ECmsCloseSubsession ); |
|
233 } |
|
234 |
|
235 // ---------------------------------------------------- |
|
236 // RCmsContact::Subscribe |
|
237 // |
|
238 // ---------------------------------------------------- |
|
239 // |
|
240 EXPORT_C void RCmsContact::OrderNotificationsL( |
|
241 MCmsNotificationHandlerAPI* aHandler, |
|
242 CCmsContactFieldItem::TCmsContactNotification aNotificationType ) |
|
243 { |
|
244 #ifdef _DEBUG |
|
245 RCmsSession::WriteToLog( _L8( "RCmsContact::OrderNotificationsL()" ) ); |
|
246 #endif |
|
247 // We have to create separate notifiers for Presence and Phonebook events. |
|
248 // There are two separate queues in the CSM server, that's why. |
|
249 if ( aNotificationType & CCmsContactFieldItem::ECmsPresenceAllNotification ) |
|
250 { |
|
251 // mask phonebook bits off. |
|
252 TUint myMask = aNotificationType & CCmsContactFieldItem::ECmsPresenceAllNotification; |
|
253 CCmsContactNotifier* notifier = CreateNotifierL( aHandler, (CCmsContactFieldItem::TCmsContactNotification)myMask ); |
|
254 notifier->StartOrderL(); |
|
255 } |
|
256 |
|
257 if ( aNotificationType & CCmsContactFieldItem::ECmsPhonebookNotification ) |
|
258 { |
|
259 CCmsContactNotifier* notifier = CreateNotifierL( aHandler, CCmsContactFieldItem::ECmsPhonebookNotification ); |
|
260 notifier->StartOrderL(); |
|
261 } |
|
262 } |
|
263 |
|
264 // ---------------------------------------------------- |
|
265 // RCmsContact::UnSubscribe |
|
266 // |
|
267 // ---------------------------------------------------- |
|
268 // |
|
269 |
|
270 EXPORT_C void RCmsContact::CancelNotifications( |
|
271 CCmsContactFieldItem::TCmsContactNotification aNotificationType ) |
|
272 { |
|
273 #ifdef _DEBUG |
|
274 RCmsSession::WriteToLog( _L8( "RCmsContact::CancelNotifications()" ) ); |
|
275 #endif |
|
276 DeleteNotifier( aNotificationType ); |
|
277 } |
|
278 |
|
279 // ---------------------------------------------------- |
|
280 // RCmsContact::UnSubscribe |
|
281 // |
|
282 // ---------------------------------------------------- |
|
283 // |
|
284 EXPORT_C TInt RCmsContact::GetContactActionFieldCount( |
|
285 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aContactAction) |
|
286 { |
|
287 return SendReceive( ECmsGetContactActionFieldCount, TIpcArgs( aContactAction ) ); |
|
288 } |
|
289 |
|
290 // ---------------------------------------------------- |
|
291 // RCmsContact::SetVoiceCallDefault |
|
292 // |
|
293 // ---------------------------------------------------- |
|
294 // |
|
295 EXPORT_C void RCmsContact::SetVoiceCallDefault( TRequestStatus& aStatus ) const |
|
296 { |
|
297 SendReceive( ECmsSetVoiceCallDefault, TIpcArgs(), aStatus ); |
|
298 } |
|
299 |
|
300 // ---------------------------------------------------- |
|
301 // RCmsContact::SendMessage |
|
302 // |
|
303 // ---------------------------------------------------- |
|
304 // |
|
305 void RCmsContact::SendMessage( TInt aServerMessage, |
|
306 CCmsContactBase& aContactField, |
|
307 CCmsContactFieldItem::TCmsContactField aFieldType ) |
|
308 { |
|
309 #ifdef _DEBUG |
|
310 RCmsSession::WriteToLog( _L8( "RCmsContact::SendMessage()" ) ); |
|
311 #endif |
|
312 if( aContactField.IsBinary() ) |
|
313 { |
|
314 SendReceive( aServerMessage, TIpcArgs( |
|
315 aFieldType, aContactField.StreamDesc8() ), aContactField.Activate() ); |
|
316 } |
|
317 else |
|
318 { |
|
319 SendReceive( aServerMessage, TIpcArgs( |
|
320 aFieldType, aContactField.StreamDesc16() ), aContactField.Activate() ); |
|
321 } |
|
322 } |
|
323 |
|
324 // ---------------------------------------------------- |
|
325 // RCmsContact::SendMessage |
|
326 // |
|
327 // ---------------------------------------------------- |
|
328 // |
|
329 void RCmsContact::SendMessage( TInt aServerMessage, |
|
330 CCmsContactBase& aContactField, |
|
331 CCmsContactFieldItem::TCmsContactFieldGroup aFieldGroup ) |
|
332 { |
|
333 #ifdef _DEBUG |
|
334 RCmsSession::WriteToLog( _L8( "RCmsContact::SendMessage()" ) ); |
|
335 #endif |
|
336 if( aContactField.IsBinary() ) |
|
337 { |
|
338 SendReceive( aServerMessage, TIpcArgs( |
|
339 aFieldGroup, aContactField.StreamDesc8() ), aContactField.Activate() ); |
|
340 } |
|
341 else |
|
342 { |
|
343 SendReceive( aServerMessage, TIpcArgs( |
|
344 aFieldGroup, aContactField.StreamDesc16() ), aContactField.Activate() ); |
|
345 } |
|
346 } |
|
347 |
|
348 // ---------------------------------------------------- |
|
349 // RCmsContact::SendMessage |
|
350 // |
|
351 // ---------------------------------------------------- |
|
352 // |
|
353 void RCmsContact::SendMessage( TInt aServerMessage, |
|
354 TIpcArgs& aArguments, |
|
355 TRequestStatus& aStatus ) |
|
356 { |
|
357 #ifdef _DEBUG |
|
358 RCmsSession::WriteToLog( _L8( "RCmsContact::SendMessage()" ) ); |
|
359 #endif |
|
360 SendReceive( aServerMessage, aArguments, aStatus ); |
|
361 } |
|
362 |
|
363 // ---------------------------------------------------- |
|
364 // RCmsContact::SendMessage |
|
365 // |
|
366 // ---------------------------------------------------- |
|
367 // |
|
368 void RCmsContact::SendMessage( TInt aServerMessage, |
|
369 TIpcArgs& aArguments ) |
|
370 { |
|
371 #ifdef _DEBUG |
|
372 RCmsSession::WriteToLog( _L8( "RCmsContact::SendMessage()" ) ); |
|
373 #endif |
|
374 SendReceive( aServerMessage, aArguments ); |
|
375 } |
|
376 |
|
377 // ---------------------------------------------------- |
|
378 // RCmsContact::ResendReceive |
|
379 // |
|
380 // ---------------------------------------------------- |
|
381 // |
|
382 void RCmsContact::ResendReceive( TInt aOperation ) |
|
383 { |
|
384 #ifdef _DEBUG |
|
385 RCmsSession::WriteToLog( _L8( "RCmsContact::ResendReceive()" ) ); |
|
386 #endif |
|
387 SendReceive( aOperation, TIpcArgs() ); |
|
388 } |
|
389 |
|
390 // ---------------------------------------------------- |
|
391 // RCmsContact::ResendReceive |
|
392 // |
|
393 // ---------------------------------------------------- |
|
394 // |
|
395 void RCmsContact::ResendReceive( TInt aOperation, |
|
396 TRequestStatus& aStatus, |
|
397 const TIpcArgs& aArguments ) |
|
398 { |
|
399 #ifdef _DEBUG |
|
400 RCmsSession::WriteToLog( _L8( "RCmsContact::ResendReceive()" ) ); |
|
401 #endif |
|
402 SendReceive( aOperation, aArguments, aStatus ); |
|
403 } |
|
404 |
|
405 // ---------------------------------------------------- |
|
406 // RCmsContact::CreateNotifierL |
|
407 // |
|
408 // ---------------------------------------------------- |
|
409 // |
|
410 CCmsContactNotifier* RCmsContact::CreateNotifierL( |
|
411 MCmsNotificationHandlerAPI* aHandler, |
|
412 CCmsContactFieldItem::TCmsContactNotification aNotificationType ) |
|
413 { |
|
414 CCmsContactNotifier* current = NULL; |
|
415 TInt count = iNotifiers.Count(); |
|
416 for ( TInt i = 0; i < count; ++i ) |
|
417 { |
|
418 current = iNotifiers[i]; |
|
419 if ( current->Type() == aNotificationType ) |
|
420 { |
|
421 User::Leave( KErrAlreadyExists ); |
|
422 } |
|
423 } |
|
424 // create a new notifier |
|
425 current = CCmsContactNotifier::NewL( *this, *aHandler, aNotificationType); |
|
426 User::LeaveIfError( iNotifiers.Append( current ) ); |
|
427 return current; |
|
428 } |
|
429 |
|
430 // ---------------------------------------------------- |
|
431 // RCmsContact::DeleteNotifier |
|
432 // |
|
433 // ---------------------------------------------------- |
|
434 // |
|
435 void RCmsContact::DeleteNotifier( |
|
436 CCmsContactFieldItem::TCmsContactNotification aNotificationType ) |
|
437 { |
|
438 CCmsContactNotifier* current = NULL; |
|
439 TInt count = iNotifiers.Count(); |
|
440 for ( TInt i = count-1; i >= 0; i-- ) |
|
441 { |
|
442 current = iNotifiers[i]; |
|
443 if ( current->Type() & aNotificationType ) |
|
444 { |
|
445 iNotifiers.Remove(i); |
|
446 iNotifiers.Compress(); |
|
447 delete current; |
|
448 } |
|
449 } |
|
450 } |
|
451 |
|
452 // ---------------------------------------------------- |
|
453 // RCmsContact::IsTopContact |
|
454 // |
|
455 // ---------------------------------------------------- |
|
456 // |
|
457 EXPORT_C TBool RCmsContact::IsTopContact() |
|
458 { |
|
459 #ifdef _DEBUG |
|
460 RCmsSession::WriteToLog( _L8( "RCmsContact::IsTopContact()" ) ); |
|
461 #endif |
|
462 TInt isTop( EFalse ); |
|
463 TPckg<TInt> pack( isTop ); |
|
464 SendReceive(ECmsIsTopContact, TIpcArgs(&pack)); |
|
465 |
|
466 return isTop; |
|
467 } |
|
468 |
|
469 |