|
1 /* |
|
2 * Copyright (c) 2002-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: A command for editing a contact |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbk2EditContactCmd.h" |
|
22 |
|
23 // Phonebook 2 |
|
24 #include <TPbk2ContactEditorParams.h> |
|
25 #include <CPbk2ContactEditorDlg.h> |
|
26 #include <MPbk2CommandObserver.h> |
|
27 #include <MPbk2ContactUiControl.h> |
|
28 #include <CPbk2AppUiBase.h> |
|
29 #include <CPbk2PresentationContact.h> |
|
30 #include <CPbk2FieldPropertyArray.h> |
|
31 #include <CPbk2PresentationContactFieldCollection.h> |
|
32 #include <CPbk2ApplicationServices.h> |
|
33 |
|
34 // Virtual Phonebook |
|
35 #include <CVPbkContactManager.h> |
|
36 #include <MVPbkContactStore.h> |
|
37 #include <MVPbkStoreContact.h> |
|
38 #include <MVPbkContactLink.h> |
|
39 #include <MVPbkContactOperationBase.h> |
|
40 #include <MVPbkContactStoreProperties.h> |
|
41 #include <VPbkUtils.h> |
|
42 |
|
43 // System includes |
|
44 #include <coemain.h> |
|
45 |
|
46 |
|
47 #ifdef _DEBUG |
|
48 namespace |
|
49 { |
|
50 enum TPanicCode |
|
51 { |
|
52 EExecuteLD_PreCond, |
|
53 EVPbkSingleContactOperationComplete_PreCond, |
|
54 EPanicPreCond_Null_Pointer |
|
55 }; |
|
56 |
|
57 void Panic(TInt aReason) |
|
58 { |
|
59 _LIT(KPanicText, "k2EditContactCmd"); |
|
60 User::Panic(KPanicText, aReason); |
|
61 } |
|
62 } |
|
63 #endif // _DEBUG |
|
64 |
|
65 // -------------------------------------------------------------------------- |
|
66 // CPbk2EditContactCmd::CPbk2EditContactCmd |
|
67 // C++ default constructor can NOT contain any code, that |
|
68 // might leave. |
|
69 // -------------------------------------------------------------------------- |
|
70 // |
|
71 CPbk2EditContactCmd::CPbk2EditContactCmd( |
|
72 MPbk2ContactUiControl& aUiControl) : |
|
73 iUiControl( &aUiControl ), |
|
74 iIsEditingAborted( EFalse ) |
|
75 { |
|
76 iUiControl->RegisterCommand( this ); |
|
77 } |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // CPbk2EditContactCmd::~CPbk2EditContactCmd |
|
81 // -------------------------------------------------------------------------- |
|
82 // |
|
83 CPbk2EditContactCmd::~CPbk2EditContactCmd() |
|
84 { |
|
85 delete iContactLink; |
|
86 delete iContact; |
|
87 delete iContactRetriever; |
|
88 if ( iUiControl ) |
|
89 { |
|
90 iUiControl->RegisterCommand( NULL ); |
|
91 } |
|
92 Release( iAppServices ); |
|
93 } |
|
94 |
|
95 // -------------------------------------------------------------------------- |
|
96 // CPbk2EditContactCmd::NewL |
|
97 // Two-phased constructor. |
|
98 // -------------------------------------------------------------------------- |
|
99 // |
|
100 CPbk2EditContactCmd* CPbk2EditContactCmd::NewL( |
|
101 MPbk2ContactUiControl& aUiControl) |
|
102 { |
|
103 CPbk2EditContactCmd* self = new( ELeave ) CPbk2EditContactCmd(aUiControl); |
|
104 CleanupStack::PushL( self ); |
|
105 self->ConstructL(); |
|
106 CleanupStack::Pop( self ); |
|
107 return self; |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // CPbk2EditContactCmd::ConstructL |
|
112 // Symbian 2nd phase constructor can leave. |
|
113 // -------------------------------------------------------------------------- |
|
114 // |
|
115 void CPbk2EditContactCmd::ConstructL() |
|
116 { |
|
117 iAppServices = CPbk2ApplicationServices::InstanceL(); |
|
118 const MVPbkBaseContact* contact = iUiControl->FocusedContactL(); |
|
119 __ASSERT_DEBUG(contact, Panic(EPanicPreCond_Null_Pointer)); |
|
120 |
|
121 User::LeaveIfNull( contact ); |
|
122 |
|
123 iContactLink = contact->CreateLinkLC(); |
|
124 CleanupStack::Pop(); |
|
125 } |
|
126 |
|
127 // -------------------------------------------------------------------------- |
|
128 // CPbk2EditContactCmd::ExecuteLD |
|
129 // -------------------------------------------------------------------------- |
|
130 // |
|
131 void CPbk2EditContactCmd::ExecuteLD() |
|
132 { |
|
133 CleanupStack::PushL(this); |
|
134 iContactRetriever = iAppServices->ContactManager().RetrieveContactL( |
|
135 *iContactLink, *this); |
|
136 CleanupStack::Pop(this); |
|
137 } |
|
138 |
|
139 // -------------------------------------------------------------------------- |
|
140 // CPbk2EditContactCmd::AddObserver |
|
141 // -------------------------------------------------------------------------- |
|
142 // |
|
143 void CPbk2EditContactCmd::AddObserver(MPbk2CommandObserver& aObserver) |
|
144 { |
|
145 iCommandObserver = &aObserver; |
|
146 } |
|
147 |
|
148 // -------------------------------------------------------------------------- |
|
149 // CPbk2EditContactCmd::ResetUiControl |
|
150 // -------------------------------------------------------------------------- |
|
151 // |
|
152 void CPbk2EditContactCmd::ResetUiControl( |
|
153 MPbk2ContactUiControl& aUiControl) |
|
154 { |
|
155 if (iUiControl == &aUiControl) |
|
156 { |
|
157 iUiControl = NULL; |
|
158 } |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------- |
|
162 // CPbk2EditContactCmd::VPbkSingleContactOperationComplete |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 void CPbk2EditContactCmd::VPbkSingleContactOperationComplete( |
|
166 MVPbkContactOperationBase& /*aOperation*/, |
|
167 MVPbkStoreContact* aContact) |
|
168 { |
|
169 __ASSERT_DEBUG(aContact, |
|
170 Panic(EVPbkSingleContactOperationComplete_PreCond)); |
|
171 |
|
172 __ASSERT_DEBUG(iCommandObserver, Panic(EPanicPreCond_Null_Pointer)); |
|
173 |
|
174 if (aContact) |
|
175 { |
|
176 iContact = aContact; |
|
177 TRAPD( error, iContact->LockL(*this) ); |
|
178 if ( error != KErrNone ) |
|
179 { |
|
180 iCommandObserver->CommandFinished(*this); |
|
181 CCoeEnv::Static()->HandleError(error); |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 // -------------------------------------------------------------------------- |
|
187 // CPbk2EditContactCmd::VPbkSingleContactOperationFailed |
|
188 // -------------------------------------------------------------------------- |
|
189 // |
|
190 void CPbk2EditContactCmd::VPbkSingleContactOperationFailed |
|
191 (MVPbkContactOperationBase& /*aOperation*/, TInt aError) |
|
192 { |
|
193 __ASSERT_DEBUG(iCommandObserver, Panic(EPanicPreCond_Null_Pointer)); |
|
194 |
|
195 iCommandObserver->CommandFinished(*this); |
|
196 CCoeEnv::Static()->HandleError(aError); |
|
197 } |
|
198 |
|
199 // -------------------------------------------------------------------------- |
|
200 // CPbk2EditContactCmd::ContactOperationCompleted |
|
201 // -------------------------------------------------------------------------- |
|
202 // |
|
203 void CPbk2EditContactCmd::ContactOperationCompleted |
|
204 (TContactOpResult /*aResult*/) |
|
205 { |
|
206 // open editing dialog |
|
207 TRAPD(result, ExecuteEditorL()); |
|
208 iCommandObserver->CommandFinished(*this); |
|
209 if (result != KErrNone) |
|
210 { |
|
211 CCoeEnv::Static()->HandleError(result); |
|
212 } |
|
213 } |
|
214 |
|
215 // -------------------------------------------------------------------------- |
|
216 // CPbk2EditContactCmd::ContactOperationFailed |
|
217 // -------------------------------------------------------------------------- |
|
218 // |
|
219 void CPbk2EditContactCmd::ContactOperationFailed |
|
220 (TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/) |
|
221 { |
|
222 __ASSERT_DEBUG(iCommandObserver, Panic(EPanicPreCond_Null_Pointer)); |
|
223 |
|
224 iCommandObserver->CommandFinished(*this); |
|
225 CCoeEnv::Static()->HandleError(aErrorCode); |
|
226 } |
|
227 |
|
228 // -------------------------------------------------------------------------- |
|
229 // CPbk2EditContactCmd::ContactEditingComplete |
|
230 // -------------------------------------------------------------------------- |
|
231 // |
|
232 void CPbk2EditContactCmd::ContactEditingComplete |
|
233 (MVPbkStoreContact* aEditedContact) |
|
234 { |
|
235 iContact = aEditedContact; |
|
236 } |
|
237 |
|
238 // -------------------------------------------------------------------------- |
|
239 // CPbk2EditContactCmd::ContactEditingDeletedContact |
|
240 // -------------------------------------------------------------------------- |
|
241 // |
|
242 void CPbk2EditContactCmd::ContactEditingDeletedContact |
|
243 (MVPbkStoreContact* aEditedContact) |
|
244 { |
|
245 iContact = aEditedContact; |
|
246 } |
|
247 |
|
248 // -------------------------------------------------------------------------- |
|
249 // CPbk2EditContactCmd::ContactEditingAborted |
|
250 // -------------------------------------------------------------------------- |
|
251 // |
|
252 void CPbk2EditContactCmd::ContactEditingAborted() |
|
253 { |
|
254 iIsEditingAborted = ETrue; |
|
255 } |
|
256 |
|
257 // -------------------------------------------------------------------------- |
|
258 // CPbk2EditContactCmd::ExecuteEditorL |
|
259 // -------------------------------------------------------------------------- |
|
260 // |
|
261 void CPbk2EditContactCmd::ExecuteEditorL() |
|
262 { |
|
263 // verify syncronization field existance and content |
|
264 VPbkUtils::VerifySyncronizationFieldL( |
|
265 CCoeEnv::Static()->FsSession(), |
|
266 iContact->ParentStore().StoreProperties().SupportedFields(), |
|
267 *iContact ); |
|
268 |
|
269 // adjust focus |
|
270 TInt focusedFieldIndex = KErrNotFound; |
|
271 if (iUiControl) |
|
272 { |
|
273 focusedFieldIndex = iUiControl->FocusedFieldIndex(); |
|
274 } |
|
275 |
|
276 TPbk2ContactEditorParams params; |
|
277 if ( focusedFieldIndex != KErrNotFound ) |
|
278 { |
|
279 params.iFocusedContactField = |
|
280 FocusedFieldLC( *iContact ); |
|
281 } |
|
282 |
|
283 // create and execute editing dialog |
|
284 CPbk2ContactEditorDlg* dlg = |
|
285 CPbk2ContactEditorDlg::NewL( params, iContact, *this ); |
|
286 iContact = NULL; // ownership went to editor |
|
287 dlg->ExecuteLD(); |
|
288 |
|
289 // clean after dialog execution |
|
290 if ( focusedFieldIndex != KErrNotFound ) |
|
291 { |
|
292 CleanupStack::PopAndDestroy(); //params.iFocusedContactField |
|
293 } |
|
294 |
|
295 if (iUiControl) |
|
296 { |
|
297 iUiControl->ResetFindL(); |
|
298 |
|
299 // If editing has been aborted we don't set focused contact. |
|
300 if ( iContact && !iIsEditingAborted) |
|
301 { |
|
302 // It is possible that the contact got changed while in edit |
|
303 iUiControl->SetFocusedFieldIndex( params.iFocusedIndex ); |
|
304 iUiControl->SetFocusedContactL( *iContact ); |
|
305 } |
|
306 |
|
307 // If contact got deleted in the editor, this call ensures |
|
308 // that the contact info view is switched to the names list |
|
309 iUiControl->UpdateAfterCommandExecution(); |
|
310 } |
|
311 } |
|
312 |
|
313 MVPbkStoreContactField* CPbk2EditContactCmd::FocusedFieldLC |
|
314 ( MVPbkStoreContact& aStoreContact ) |
|
315 { |
|
316 CPbk2PresentationContact* presentationContact = |
|
317 CPbk2PresentationContact::NewL( aStoreContact, |
|
318 iAppServices->FieldProperties() ); |
|
319 CleanupStack::PushL( presentationContact ); |
|
320 |
|
321 TInt index = KErrNotFound; |
|
322 if (iUiControl) |
|
323 { |
|
324 index = presentationContact->PresentationFields().StoreIndexOfField( |
|
325 iUiControl->FocusedFieldIndex() ); |
|
326 } |
|
327 |
|
328 CleanupStack::PopAndDestroy( presentationContact ); |
|
329 |
|
330 if ( index != KErrNotFound ) |
|
331 { |
|
332 // Use FieldAtLC to avoid the unvalidity of the field after new |
|
333 // FieldAt call. |
|
334 return aStoreContact.Fields().FieldAtLC( index ); |
|
335 } |
|
336 return NULL; |
|
337 } |
|
338 |
|
339 // End of File |