|
1 /* |
|
2 * Copyright (c) 2006-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 the License "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: Implements the contact callback interface. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <LiwCommon.h> |
|
20 #include <LiwGenericParam.h> |
|
21 |
|
22 // User Includes |
|
23 #include "contactinterfacecallback.h" |
|
24 #include "contactinterface.h" |
|
25 #include "contacterrormessage.hrh" |
|
26 #include "../../inc/serviceerrno.h" |
|
27 #include "searchfields.h" |
|
28 |
|
29 //_LIT8(KResponse,"ReturnValue"); |
|
30 //_LIT(KAddFieldKeyNotSupported,"Contacts : Add :Field Key Not Supported on this Database: "); |
|
31 /* |
|
32 ----------------------------------------------------------------------------- |
|
33 CContactInterfaceCallback::CContactInterfaceCallback() |
|
34 Description : Symbian default Constructor can NOT contain |
|
35 any code that might leave. |
|
36 Return values : N/A |
|
37 ----------------------------------------------------------------------------- |
|
38 */ |
|
39 CContactInterfaceCallback::CContactInterfaceCallback() |
|
40 :iCallback(NULL), |
|
41 iTransactionId(0), |
|
42 iInParamList(NULL), |
|
43 iEventParamList(NULL), |
|
44 iContact(NULL) |
|
45 { |
|
46 } |
|
47 |
|
48 /* |
|
49 ----------------------------------------------------------------------------- |
|
50 CContactInterfaceCallback::NewL() |
|
51 Description : Two-phased constructor. |
|
52 Return values : CContactInterfaceCallback object pointer |
|
53 ----------------------------------------------------------------------------- |
|
54 */ |
|
55 CContactInterfaceCallback* CContactInterfaceCallback::NewL() |
|
56 { |
|
57 return new ( ELeave ) CContactInterfaceCallback(); |
|
58 } |
|
59 |
|
60 /* |
|
61 ----------------------------------------------------------------------------- |
|
62 CContactInterfaceCallback::NewL() |
|
63 Description : Two-phased overloaded constructor. |
|
64 Return values : CContactInterfaceCallback object pointer |
|
65 ----------------------------------------------------------------------------- |
|
66 */ |
|
67 CContactInterfaceCallback* CContactInterfaceCallback::NewL(CSingleContact* aContact) |
|
68 { |
|
69 CContactInterfaceCallback* self = new (ELeave) CContactInterfaceCallback(); |
|
70 self->iContact = aContact; |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 /* |
|
76 ----------------------------------------------------------------------------- |
|
77 CContactInterfaceCallback::~CContactInterfaceCallback() |
|
78 Description : Destructor, free allocated resources |
|
79 Return values : N/A |
|
80 ----------------------------------------------------------------------------- |
|
81 */ |
|
82 CContactInterfaceCallback::~CContactInterfaceCallback() |
|
83 { |
|
84 delete iEventParamList; |
|
85 delete iContact; |
|
86 } |
|
87 |
|
88 /* |
|
89 ----------------------------------------------------------------------------- |
|
90 CContactInterfaceCallback::SetParams() |
|
91 Description : Sets the basic params of the callback object |
|
92 Return values : N/A |
|
93 ----------------------------------------------------------------------------- |
|
94 */ |
|
95 void CContactInterfaceCallback::SetParams( MLiwNotifyCallback* aCallback, |
|
96 const TInt aTransId, |
|
97 const CLiwGenericParamList* aInParamList ) |
|
98 { |
|
99 iCallback = aCallback; |
|
100 iTransactionId = aTransId; |
|
101 iInParamList = aInParamList; |
|
102 } |
|
103 |
|
104 /* |
|
105 ----------------------------------------------------------------------------- |
|
106 CContactInterfaceCallback::HandleReturnValue() |
|
107 Description : The MContactCallback Method, is called when |
|
108 Error has occured.The Error is passed |
|
109 to the consumer by appending to the CLiwGenericParamList. |
|
110 Return values : N/A |
|
111 ----------------------------------------------------------------------------- |
|
112 */ |
|
113 void CContactInterfaceCallback::HandleReturnValue( TOperationEvent aEventId, const TInt& aError,TInt aTransId) |
|
114 { |
|
115 TInt err = 0; |
|
116 CleanupStack::PushL(this); |
|
117 if( iCallback ) |
|
118 { |
|
119 if( iEventParamList ) |
|
120 { |
|
121 iEventParamList->Reset(); |
|
122 } |
|
123 else |
|
124 { |
|
125 iEventParamList = CLiwGenericParamList::NewL(); |
|
126 } |
|
127 |
|
128 if(aEventId == EOpCancel) |
|
129 { |
|
130 iEventParamList->AppendL(TLiwGenericParam(KErrorCode, |
|
131 TLiwVariant((TInt32)SErrCancelSuccess ))); |
|
132 //Call HandleNotify |
|
133 TRAP(err,iCallback->HandleNotifyL((TInt32)aTransId, |
|
134 KLiwEventCanceled, |
|
135 *iEventParamList, |
|
136 *iInParamList)); |
|
137 } |
|
138 else if(aEventId == EOpError) |
|
139 { |
|
140 TInt32 sapiError = CContactInterface::SapiError(aError); |
|
141 iEventParamList->AppendL(TLiwGenericParam( KErrorCode, |
|
142 TLiwVariant((TInt32)sapiError))); |
|
143 //Call HandleNotify |
|
144 TRAP(err,iCallback->HandleNotifyL((TInt32)aTransId, |
|
145 KLiwEventError, |
|
146 *iEventParamList, |
|
147 *iInParamList)); |
|
148 } |
|
149 else if(aEventId == EInvalidKey) |
|
150 { |
|
151 TPtrC8 ptr = CSearchFields::GetFieldKeyFromId(aError); |
|
152 TBuf<25> buff; |
|
153 buff.Copy(ptr); |
|
154 TBuf<KMaxName> errmsg(KAddFieldKeyNotSupported); |
|
155 errmsg.Append(buff); |
|
156 |
|
157 const_cast<TInt&> (aError) = KErrNotSupported; |
|
158 TInt32 sapiError = CContactInterface::SapiError(aError); |
|
159 |
|
160 iEventParamList->AppendL(TLiwGenericParam( KErrorCode, |
|
161 TLiwVariant((TInt32)sapiError))); |
|
162 |
|
163 iEventParamList->AppendL(TLiwGenericParam(KErrorMessage, |
|
164 TLiwVariant(errmsg))); |
|
165 //Call HandleNotify |
|
166 TRAP(err,iCallback->HandleNotifyL((TInt32)aTransId, |
|
167 KLiwEventError, |
|
168 *iEventParamList, |
|
169 *iInParamList)); |
|
170 } |
|
171 else |
|
172 { |
|
173 //Append Error code |
|
174 TInt32 sapiError = CContactInterface::SapiError(aError); |
|
175 iEventParamList->AppendL(TLiwGenericParam( KErrorCode, |
|
176 TLiwVariant( (TInt32)sapiError ))); |
|
177 //Append Reason |
|
178 |
|
179 //Call HandleNotify |
|
180 TRAP(err,iCallback->HandleNotifyL((TInt32)aTransId, |
|
181 KLiwEventCompleted, |
|
182 *iEventParamList, |
|
183 *iInParamList)); |
|
184 } |
|
185 |
|
186 } |
|
187 CleanupStack::PopAndDestroy(this); |
|
188 } |
|
189 /* |
|
190 ----------------------------------------------------------------------------- |
|
191 CContactInterfaceCallback::HandleReturnIter() |
|
192 Description : The MContactCallback Method, is called when |
|
193 GetList returns an iterator on a list of entries retrived. |
|
194 Return values : N/A |
|
195 ----------------------------------------------------------------------------- |
|
196 */ |
|
197 |
|
198 |
|
199 void CContactInterfaceCallback::HandleReturnIter(const TInt& aError, |
|
200 CContactIter* aIter, |
|
201 TInt aTransId) |
|
202 { |
|
203 TInt err = 0; |
|
204 CleanupStack::PushL(this); |
|
205 if( iCallback ) |
|
206 { |
|
207 if( iEventParamList ) |
|
208 { |
|
209 iEventParamList->Reset(); |
|
210 } |
|
211 else |
|
212 { |
|
213 iEventParamList = CLiwGenericParamList::NewL(); |
|
214 } |
|
215 //Append Error Code |
|
216 TInt32 sapiError = CContactInterface::SapiError(aError); |
|
217 iEventParamList->AppendL(TLiwGenericParam( KErrorCode, |
|
218 TLiwVariant((TInt32)sapiError))); |
|
219 |
|
220 if(aIter) |
|
221 { |
|
222 CContactIterator* iterator=CContactIterator::NewL(aIter); |
|
223 CleanupStack::PushL(iterator); |
|
224 //Append Iterator in case it is valid |
|
225 iEventParamList->AppendL(TLiwGenericParam(KReturnValue, |
|
226 TLiwVariant(iterator))); |
|
227 iterator->DecRef(); |
|
228 CleanupStack::Pop(iterator); |
|
229 } |
|
230 |
|
231 //Call HandleNotify |
|
232 TRAP(err,iCallback->HandleNotifyL(aTransId, |
|
233 KLiwEventCompleted, |
|
234 *iEventParamList, |
|
235 *iInParamList)); |
|
236 } |
|
237 CleanupStack::PopAndDestroy(this); |
|
238 } |