|
1 /* |
|
2 * Copyright (c) 2009 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: A contact editor strategy for the new own contact creation |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "cpbk2contacteditornewowncontact.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include <TPbk2ContactEditorParams.h> |
|
23 #include <CPbk2PresentationContact.h> |
|
24 #include "CPbk2InputAbsorber.h" |
|
25 #include <Pbk2Debug.h> |
|
26 #include <csxhelp/phob.hlp.hrh> |
|
27 #include <Pbk2UID.h> |
|
28 |
|
29 // Virtual Phonebook |
|
30 #include <MVPbkStoreContact.h> |
|
31 |
|
32 // System includes |
|
33 #include <avkon.rsg> |
|
34 |
|
35 |
|
36 #ifdef _DEBUG |
|
37 |
|
38 /// Unnamed namespace |
|
39 namespace { |
|
40 enum TPanicCode |
|
41 { |
|
42 EContactOperationCompleted_PreCond, |
|
43 EContactOperationFailed_PreCond, |
|
44 EDeleteContactL_PreCond |
|
45 }; |
|
46 |
|
47 void Panic(TInt aReason) |
|
48 { |
|
49 _LIT(KPanicText, "EditorNewOwnContact"); |
|
50 User::Panic(KPanicText, aReason); |
|
51 } |
|
52 } /// namespace |
|
53 |
|
54 #endif // _DEBUG |
|
55 |
|
56 // -------------------------------------------------------------------------- |
|
57 // CPbk2ContactEditorNewOwnContact::CPbk2ContactEditorNewOwnContact |
|
58 // -------------------------------------------------------------------------- |
|
59 // |
|
60 inline CPbk2ContactEditorNewOwnContact::CPbk2ContactEditorNewOwnContact( |
|
61 CPbk2PresentationContact* aContact ) : |
|
62 CActive( CActive::EPriorityStandard ), |
|
63 iContact( aContact ) |
|
64 { |
|
65 CActiveScheduler::Add(this); |
|
66 } |
|
67 |
|
68 // -------------------------------------------------------------------------- |
|
69 // CPbk2ContactEditorNewOwnContact::~CPbk2ContactEditorNewOwnContact |
|
70 // -------------------------------------------------------------------------- |
|
71 // |
|
72 CPbk2ContactEditorNewOwnContact::~CPbk2ContactEditorNewOwnContact() |
|
73 { |
|
74 Cancel(); |
|
75 delete iIdleDelete; |
|
76 delete iInputAbsorber; |
|
77 } |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // CPbk2ContactEditorNewOwnContact::NewL |
|
81 // -------------------------------------------------------------------------- |
|
82 // |
|
83 CPbk2ContactEditorNewOwnContact* CPbk2ContactEditorNewOwnContact::NewL( |
|
84 TPbk2ContactEditorParams& /*aParams*/, |
|
85 CPbk2PresentationContact* aContact ) |
|
86 { |
|
87 CPbk2ContactEditorNewOwnContact* self = |
|
88 new(ELeave) CPbk2ContactEditorNewOwnContact(aContact); |
|
89 CleanupStack::PushL(self); |
|
90 self->ConstructL(); |
|
91 CleanupStack::Pop(self); |
|
92 return self; |
|
93 } |
|
94 |
|
95 // -------------------------------------------------------------------------- |
|
96 // CPbk2ContactEditorNewOwnContact::ConstructL |
|
97 // -------------------------------------------------------------------------- |
|
98 // |
|
99 inline void CPbk2ContactEditorNewOwnContact::ConstructL() |
|
100 { |
|
101 iContact->AddSupportedTemplateFieldsL(); |
|
102 iInputAbsorber = CPbk2InputAbsorber::NewL(R_AVKON_SOFTKEYS_OPTIONS_DONE); |
|
103 } |
|
104 |
|
105 // -------------------------------------------------------------------------- |
|
106 // CPbk2ContactEditorNewOwnContact::RunL |
|
107 // -------------------------------------------------------------------------- |
|
108 // |
|
109 void CPbk2ContactEditorNewOwnContact::RunL() |
|
110 { |
|
111 MPbk2ContactEditorEventObserver* observer = iObserver; |
|
112 iObserver = NULL; |
|
113 observer->ContactEditorOperationCompleted(iLatestResult, iEditorParams); |
|
114 } |
|
115 |
|
116 // -------------------------------------------------------------------------- |
|
117 // CPbk2ContactEditorNewOwnContact::DoCancel |
|
118 // -------------------------------------------------------------------------- |
|
119 // |
|
120 void CPbk2ContactEditorNewOwnContact::DoCancel() |
|
121 { |
|
122 // Do nothing |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // CPbk2ContactEditorNewOwnContact::SaveContactL |
|
127 // -------------------------------------------------------------------------- |
|
128 // |
|
129 void CPbk2ContactEditorNewOwnContact::SaveContactL( |
|
130 MPbk2ContactEditorEventObserver& aObserver, |
|
131 MPbk2ContactEditorEventObserver::TParams& aParams) |
|
132 { |
|
133 // If observer is set there is process ongoing. |
|
134 // Might happen when user is quicker than should be. |
|
135 if ( !iObserver ) |
|
136 { |
|
137 iObserver = &aObserver; |
|
138 iEditorParams = aParams; |
|
139 iContact->CommitL(*this); |
|
140 iInputAbsorber->Wait(); |
|
141 } |
|
142 } |
|
143 |
|
144 // -------------------------------------------------------------------------- |
|
145 // CPbk2ContactEditorNewOwnContact::DeleteContactL |
|
146 // -------------------------------------------------------------------------- |
|
147 // |
|
148 void CPbk2ContactEditorNewOwnContact::DeleteContactL( |
|
149 MPbk2ContactEditorEventObserver& aObserver, |
|
150 MPbk2ContactEditorEventObserver::TParams& aParams) |
|
151 { |
|
152 __ASSERT_DEBUG(!iObserver, Panic(EDeleteContactL_PreCond)); |
|
153 |
|
154 if (!iIdleDelete) |
|
155 { |
|
156 iIdleDelete = CIdle::NewL(CActive::EPriorityStandard); |
|
157 } |
|
158 else |
|
159 { |
|
160 iIdleDelete->Cancel(); |
|
161 } |
|
162 |
|
163 iObserver = &aObserver; |
|
164 iEditorParams = aParams; |
|
165 iIdleDelete->Start(TCallBack(&IdleDeleteCallBack, this)); |
|
166 iInputAbsorber->Wait(); |
|
167 } |
|
168 |
|
169 // -------------------------------------------------------------------------- |
|
170 // CPbk2ContactEditorNewOwnContact::DefaultTitle |
|
171 // -------------------------------------------------------------------------- |
|
172 // |
|
173 const TDesC& CPbk2ContactEditorNewOwnContact::DefaultTitle() const |
|
174 { |
|
175 // not used |
|
176 return KNullDesC; |
|
177 } |
|
178 |
|
179 // -------------------------------------------------------------------------- |
|
180 // CPbk2ContactEditorNewOwnContact::SwitchContactL |
|
181 // -------------------------------------------------------------------------- |
|
182 // |
|
183 void CPbk2ContactEditorNewOwnContact::SwitchContactL( |
|
184 CPbk2PresentationContact* aContact) |
|
185 { |
|
186 iContact = aContact; |
|
187 } |
|
188 |
|
189 // -------------------------------------------------------------------------- |
|
190 // CPbk2ContactEditorNewOwnContact::GetHelpContext |
|
191 // -------------------------------------------------------------------------- |
|
192 // |
|
193 void CPbk2ContactEditorNewOwnContact::GetHelpContext( |
|
194 TCoeHelpContext &aContext) const |
|
195 { |
|
196 aContext.iMajor.iUid = KPbk2UID3; |
|
197 aContext.iContext = KHLP_CCA_EDITOR; |
|
198 } |
|
199 |
|
200 // -------------------------------------------------------------------------- |
|
201 // CPbk2ContactEditorNewOwnContact::StopQuery |
|
202 // -------------------------------------------------------------------------- |
|
203 // |
|
204 TBool CPbk2ContactEditorNewOwnContact::StopQuery() |
|
205 { |
|
206 return EFalse; |
|
207 } |
|
208 |
|
209 // -------------------------------------------------------------------------- |
|
210 // CPbk2ContactEditorNewOwnContact::IdleDeleteCallBack |
|
211 // -------------------------------------------------------------------------- |
|
212 // |
|
213 TInt CPbk2ContactEditorNewOwnContact::IdleDeleteCallBack( TAny* aSelf ) |
|
214 { |
|
215 static_cast<CPbk2ContactEditorNewOwnContact*>(aSelf)->HandleIdleDelete(); |
|
216 return EFalse; |
|
217 } |
|
218 |
|
219 // -------------------------------------------------------------------------- |
|
220 // CPbk2ContactEditorNewOwnContact::HandleIdleDelete |
|
221 // -------------------------------------------------------------------------- |
|
222 // |
|
223 void CPbk2ContactEditorNewOwnContact::HandleIdleDelete() |
|
224 { |
|
225 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
226 ( "CPbk2ContactEditorNewOwnContact::HandleIdleDelete(0x%x)" ), this ); |
|
227 iInputAbsorber->StopWait(); |
|
228 // Notify client asynchronously to let Delete Operation complete firstly and |
|
229 // then the client will be notified to do the other things in the RunL() function. |
|
230 iLatestResult.iExtension = NULL; |
|
231 iLatestResult.iStoreContact = NULL; |
|
232 iLatestResult.iOpCode = MVPbkContactObserver::EContactDelete; |
|
233 TRequestStatus* status = &iStatus; |
|
234 User::RequestComplete(status, KErrNone); |
|
235 SetActive(); |
|
236 } |
|
237 |
|
238 // -------------------------------------------------------------------------- |
|
239 // CPbk2ContactEditorNewOwnContact::ContactOperationCompleted |
|
240 // -------------------------------------------------------------------------- |
|
241 // |
|
242 void CPbk2ContactEditorNewOwnContact::ContactOperationCompleted( |
|
243 MVPbkContactObserver::TContactOpResult aResult ) |
|
244 { |
|
245 __ASSERT_DEBUG(iObserver && |
|
246 ( aResult.iOpCode == MVPbkContactObserver::EContactCommit || |
|
247 aResult.iOpCode == MVPbkContactObserver::EContactSetOwn ), |
|
248 Panic(EContactOperationCompleted_PreCond)); |
|
249 |
|
250 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
251 ("CPbk2ContactEditorNewOwnContact::ContactOperationCompleted(0x%x)"), |
|
252 this); |
|
253 if( aResult.iOpCode == MVPbkContactObserver::EContactCommit ) |
|
254 { |
|
255 // Set contact as own contact |
|
256 TRAPD( err, iContact->SetAsOwnL( *this ) ); |
|
257 if( err ) |
|
258 { |
|
259 ContactOperationFailed( aResult.iOpCode, err, EFalse ); |
|
260 } |
|
261 // store commit result |
|
262 iLatestResult = aResult; |
|
263 } |
|
264 else // MVPbkContactObserver::EContactSetOwn |
|
265 { |
|
266 iInputAbsorber->StopWait(); |
|
267 |
|
268 // Notify client asynchronously to give some time for the all |
|
269 // contacts view to get ready. This might not be needed anymore |
|
270 // here in new contact strategy... In edit contact strategy |
|
271 // this however is a mandatory move. |
|
272 TRequestStatus* status = &iStatus; |
|
273 User::RequestComplete(status, KErrNone); |
|
274 SetActive(); |
|
275 } |
|
276 } |
|
277 |
|
278 // -------------------------------------------------------------------------- |
|
279 // CPbk2ContactEditorNewOwnContact::ContactOperationFailed |
|
280 // -------------------------------------------------------------------------- |
|
281 // |
|
282 void CPbk2ContactEditorNewOwnContact::ContactOperationFailed( |
|
283 MVPbkContactObserver::TContactOp aOpCode, |
|
284 TInt aErrorCode, TBool aErrorNotified ) |
|
285 { |
|
286 __ASSERT_DEBUG(iObserver, Panic(EContactOperationFailed_PreCond)); |
|
287 |
|
288 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
289 ("CPbk2ContactEditorNewOwnContact::ContactOperationFailed(0x%x) aErrorCode(%d)"), |
|
290 this, aErrorCode); |
|
291 iInputAbsorber->StopWait(); |
|
292 MPbk2ContactEditorEventObserver* observer = iObserver; |
|
293 iObserver = NULL; |
|
294 |
|
295 MPbk2ContactEditorEventObserver::TFailParams failParams; |
|
296 failParams.iCloseEditor = EFalse; |
|
297 failParams.iErrorNotified = aErrorNotified; |
|
298 failParams.iErrorCode = KErrNone; |
|
299 |
|
300 observer->ContactEditorOperationFailed(aOpCode, aErrorCode, iEditorParams, |
|
301 failParams ); |
|
302 } |
|
303 |
|
304 // End of File |