|
1 /* |
|
2 * Copyright (c) 2005-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: Phonebook 2 server app contact data assign phase. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2AssignAttributePhase.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "MPbk2ServicePhaseObserver.h" |
|
23 #include "CPbk2ServerAppAppUi.h" |
|
24 #include "MPbk2ContactAssigner.h" |
|
25 #include "Pbk2ContactAssignerFactory.h" |
|
26 #include <MPbk2DialogEliminator.h> |
|
27 #include <MPbk2ApplicationServices.h> |
|
28 |
|
29 // Virtual Phonebook |
|
30 #include <MVPbkContactLink.h> |
|
31 #include <CVPbkContactLinkArray.h> |
|
32 #include <CVPbkContactManager.h> |
|
33 #include <MVPbkStoreContact.h> |
|
34 #include <MVPbkContactOperationBase.h> |
|
35 |
|
36 /// Unnamed namespace for local definitions |
|
37 namespace { |
|
38 |
|
39 const TInt KFirstElement = 0; |
|
40 |
|
41 /** |
|
42 * Copies a link array to another. |
|
43 * |
|
44 * @param aSourceLinkArray Link array which is copied |
|
45 * @param aTargetLinkArray Links are copied to this |
|
46 */ |
|
47 void CopyContactLinksL( const MVPbkContactLinkArray& aSourceLinkArray, |
|
48 CVPbkContactLinkArray& aTargetLinkArray ) |
|
49 { |
|
50 const TInt count = aSourceLinkArray.Count(); |
|
51 for ( TInt i(0); i < count; ++i ) |
|
52 { |
|
53 const MVPbkContactLink& contactLink = aSourceLinkArray.At(i); |
|
54 aTargetLinkArray.AppendL( contactLink.CloneLC() ); |
|
55 CleanupStack::Pop(); // link |
|
56 } |
|
57 } |
|
58 |
|
59 } /// namespace |
|
60 |
|
61 // -------------------------------------------------------------------------- |
|
62 // CPbk2AssignAttributePhase::CPbk2AssignAttributePhase |
|
63 // -------------------------------------------------------------------------- |
|
64 // |
|
65 CPbk2AssignAttributePhase::CPbk2AssignAttributePhase |
|
66 ( MPbk2ServicePhaseObserver& aObserver, |
|
67 TPbk2AttributeAssignData aAttributeData, |
|
68 TBool aRemoveAttribute ) : |
|
69 iObserver( aObserver ), |
|
70 iAttributeData( aAttributeData ), |
|
71 iRemoveAttribute( aRemoveAttribute ) |
|
72 { |
|
73 } |
|
74 |
|
75 // -------------------------------------------------------------------------- |
|
76 // CPbk2AssignAttributePhase::~CPbk2AssignAttributePhase |
|
77 // -------------------------------------------------------------------------- |
|
78 // |
|
79 CPbk2AssignAttributePhase::~CPbk2AssignAttributePhase() |
|
80 { |
|
81 delete iResults; |
|
82 delete iContactLinks; |
|
83 delete iRetrieveOperation; |
|
84 delete iContactAttributeAssigner; |
|
85 delete iStoreContactField; |
|
86 delete iStoreContact; |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CPbk2AssignAttributePhase::ConstructL |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 inline void CPbk2AssignAttributePhase::ConstructL |
|
94 ( const MVPbkContactLinkArray* aContactLinks ) |
|
95 { |
|
96 iEikEnv = CEikonEnv::Static(); |
|
97 |
|
98 iContactLinks = CVPbkContactLinkArray::NewL(); |
|
99 // Take a own copy of supplied contact links |
|
100 CopyContactLinksL( *aContactLinks, *iContactLinks ); |
|
101 } |
|
102 |
|
103 // -------------------------------------------------------------------------- |
|
104 // CPbk2AssignAttributePhase::NewL |
|
105 // -------------------------------------------------------------------------- |
|
106 // |
|
107 CPbk2AssignAttributePhase* CPbk2AssignAttributePhase::NewL |
|
108 ( MPbk2ServicePhaseObserver& aObserver, |
|
109 MVPbkContactLinkArray* aContactLinks, |
|
110 TPbk2AttributeAssignData aAttributeData, |
|
111 TBool aRemoveAttribute ) |
|
112 { |
|
113 CPbk2AssignAttributePhase* self = |
|
114 new ( ELeave ) CPbk2AssignAttributePhase |
|
115 ( aObserver, aAttributeData, aRemoveAttribute ); |
|
116 CleanupStack::PushL( self ); |
|
117 self->ConstructL( aContactLinks ); |
|
118 CleanupStack::Pop( self ); |
|
119 return self; |
|
120 } |
|
121 |
|
122 // -------------------------------------------------------------------------- |
|
123 // CPbk2AssignAttributePhase::LaunchServicePhaseL |
|
124 // -------------------------------------------------------------------------- |
|
125 // |
|
126 void CPbk2AssignAttributePhase::LaunchServicePhaseL() |
|
127 { |
|
128 RetrieveContactL(); |
|
129 } |
|
130 |
|
131 // -------------------------------------------------------------------------- |
|
132 // CPbk2AssignAttributePhase::CancelServicePhase |
|
133 // -------------------------------------------------------------------------- |
|
134 // |
|
135 void CPbk2AssignAttributePhase::CancelServicePhase() |
|
136 { |
|
137 iObserver.PhaseCanceled( *this ); |
|
138 } |
|
139 |
|
140 // -------------------------------------------------------------------------- |
|
141 // CPbk2AssignAttributePhase::RequestCancelL |
|
142 // -------------------------------------------------------------------------- |
|
143 // |
|
144 void CPbk2AssignAttributePhase::RequestCancelL( TInt aExitCommandId ) |
|
145 { |
|
146 if ( aExitCommandId == EEikBidCancel ) |
|
147 { |
|
148 iObserver.PhaseAborted( *this ); |
|
149 } |
|
150 else |
|
151 { |
|
152 iObserver.PhaseCanceled( *this ); |
|
153 } |
|
154 } |
|
155 |
|
156 // -------------------------------------------------------------------------- |
|
157 // CPbk2AssignAttributePhase::AcceptDelayed |
|
158 // -------------------------------------------------------------------------- |
|
159 // |
|
160 void CPbk2AssignAttributePhase::AcceptDelayedL |
|
161 ( const TDesC8& /*aContactLinkBuffer*/ ) |
|
162 { |
|
163 // Nothing to do |
|
164 } |
|
165 |
|
166 // -------------------------------------------------------------------------- |
|
167 // CPbk2AssignAttributePhase::Results |
|
168 // -------------------------------------------------------------------------- |
|
169 // |
|
170 MVPbkContactLinkArray* CPbk2AssignAttributePhase::Results() const |
|
171 { |
|
172 return iResults; |
|
173 } |
|
174 |
|
175 // -------------------------------------------------------------------------- |
|
176 // CPbk2AssignAttributePhase::ExtraResultData |
|
177 // -------------------------------------------------------------------------- |
|
178 // |
|
179 TInt CPbk2AssignAttributePhase::ExtraResultData() const |
|
180 { |
|
181 return KErrNotSupported; |
|
182 } |
|
183 |
|
184 // -------------------------------------------------------------------------- |
|
185 // CPbk2AssignAttributePhase::TakeStoreContact |
|
186 // -------------------------------------------------------------------------- |
|
187 // |
|
188 MVPbkStoreContact* CPbk2AssignAttributePhase::TakeStoreContact() |
|
189 { |
|
190 // Not supported |
|
191 return NULL; |
|
192 } |
|
193 |
|
194 // -------------------------------------------------------------------------- |
|
195 // CPbk2AssignAttributePhase::FieldContent |
|
196 // -------------------------------------------------------------------------- |
|
197 // |
|
198 HBufC* CPbk2AssignAttributePhase::FieldContent() const |
|
199 { |
|
200 return NULL; |
|
201 } |
|
202 |
|
203 // -------------------------------------------------------------------------- |
|
204 // CPbk2AssignAttributePhase::AssignComplete |
|
205 // -------------------------------------------------------------------------- |
|
206 // |
|
207 void CPbk2AssignAttributePhase::AssignComplete |
|
208 ( MPbk2ContactAssigner& /*aAssigner*/, TInt /*aIndex*/ ) |
|
209 { |
|
210 TRAPD( err, iStoreContact->CommitL( *this ) ); |
|
211 |
|
212 if ( err != KErrNone ) |
|
213 { |
|
214 iObserver.PhaseError( *this, err ); |
|
215 } |
|
216 } |
|
217 |
|
218 // -------------------------------------------------------------------------- |
|
219 // CPbk2AssignAttributePhase::AssignFailed |
|
220 // -------------------------------------------------------------------------- |
|
221 // |
|
222 void CPbk2AssignAttributePhase::AssignFailed |
|
223 ( MPbk2ContactAssigner& /*aAssigner*/, TInt aErrorCode ) |
|
224 { |
|
225 iObserver.PhaseError( *this, aErrorCode ); |
|
226 } |
|
227 |
|
228 // -------------------------------------------------------------------------- |
|
229 // CPbk2AssignAttributePhase::VPbkSingleContactOperationComplete |
|
230 // -------------------------------------------------------------------------- |
|
231 // |
|
232 void CPbk2AssignAttributePhase::VPbkSingleContactOperationComplete |
|
233 ( MVPbkContactOperationBase& /*aOperation*/, |
|
234 MVPbkStoreContact* aContact ) |
|
235 { |
|
236 // Contact retrieval complete |
|
237 delete iStoreContact; |
|
238 iStoreContact = aContact; |
|
239 |
|
240 TRAPD( err, iStoreContact->LockL( *this ) ); |
|
241 |
|
242 if ( err != KErrNone ) |
|
243 { |
|
244 iObserver.PhaseError( *this, err ); |
|
245 } |
|
246 } |
|
247 |
|
248 // -------------------------------------------------------------------------- |
|
249 // CPbk2AssignAttributePhase::VPbkSingleContactOperationFailed |
|
250 // -------------------------------------------------------------------------- |
|
251 // |
|
252 void CPbk2AssignAttributePhase::VPbkSingleContactOperationFailed |
|
253 ( MVPbkContactOperationBase& /*aOperation*/, TInt aError ) |
|
254 { |
|
255 iObserver.PhaseError( *this, aError ); |
|
256 } |
|
257 |
|
258 // -------------------------------------------------------------------------- |
|
259 // CPbk2AssignAttributePhase::ContactOperationCompleted |
|
260 // -------------------------------------------------------------------------- |
|
261 // |
|
262 void CPbk2AssignAttributePhase::ContactOperationCompleted |
|
263 ( TContactOpResult aResult ) |
|
264 { |
|
265 if ( aResult.iOpCode == EContactLock ) |
|
266 { |
|
267 TRAPD( err, AssignAttributeL() ); |
|
268 |
|
269 if ( err != KErrNone ) |
|
270 { |
|
271 iObserver.PhaseError( *this, err ); |
|
272 } |
|
273 } |
|
274 else if ( aResult.iOpCode == EContactCommit ) |
|
275 { |
|
276 TRAPD( err, FinalizeL() ); |
|
277 |
|
278 if ( err != KErrNone ) |
|
279 { |
|
280 iObserver.PhaseError( *this, err ); |
|
281 } |
|
282 } |
|
283 } |
|
284 |
|
285 // -------------------------------------------------------------------------- |
|
286 // CPbk2AssignAttributePhase::ContactOperationFailed |
|
287 // -------------------------------------------------------------------------- |
|
288 // |
|
289 void CPbk2AssignAttributePhase::ContactOperationFailed |
|
290 ( TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/ ) |
|
291 { |
|
292 iObserver.PhaseError( *this, aErrorCode ); |
|
293 } |
|
294 |
|
295 // -------------------------------------------------------------------------- |
|
296 // CPbk2AssignAttributePhase::RetrieveContactL |
|
297 // -------------------------------------------------------------------------- |
|
298 // |
|
299 void CPbk2AssignAttributePhase::RetrieveContactL() |
|
300 { |
|
301 CPbk2ServerAppAppUi& appUi = |
|
302 static_cast<CPbk2ServerAppAppUi&> |
|
303 ( *iEikEnv->EikAppUi() ); |
|
304 |
|
305 delete iRetrieveOperation; |
|
306 iRetrieveOperation = NULL; |
|
307 iRetrieveOperation = appUi.ApplicationServices().ContactManager(). |
|
308 RetrieveContactL( iContactLinks->At( KFirstElement ), *this ); |
|
309 } |
|
310 |
|
311 // -------------------------------------------------------------------------- |
|
312 // CPbk2ContactSpeedDialAttributeAssigner::RetrieveContactFieldL |
|
313 // -------------------------------------------------------------------------- |
|
314 // |
|
315 void CPbk2AssignAttributePhase::RetrieveContactFieldL() |
|
316 { |
|
317 MVPbkStoreContactField* preSelectedField = |
|
318 iStoreContact->Fields().RetrieveField |
|
319 ( iContactLinks->At( KFirstElement ) ); |
|
320 |
|
321 if ( preSelectedField ) |
|
322 { |
|
323 // There was a pre-selected field to operate with it |
|
324 delete iStoreContactField; |
|
325 iStoreContactField = NULL; |
|
326 |
|
327 // For ownership management, clone it and operate with the clone |
|
328 iStoreContactField = preSelectedField->CloneLC(); |
|
329 CleanupStack::Pop(); // iStoreContactField |
|
330 } |
|
331 } |
|
332 |
|
333 // -------------------------------------------------------------------------- |
|
334 // CPbk2AssignAttributePhase::AppendResultL |
|
335 // -------------------------------------------------------------------------- |
|
336 // |
|
337 void CPbk2AssignAttributePhase::AppendResultL() |
|
338 { |
|
339 // Add the contact link to the result array |
|
340 if ( iStoreContactField ) |
|
341 { |
|
342 MVPbkContactLink* link = iStoreContactField->CreateLinkLC(); |
|
343 |
|
344 if ( !iResults ) |
|
345 { |
|
346 iResults = CVPbkContactLinkArray::NewL(); |
|
347 } |
|
348 |
|
349 CleanupStack::Pop(); // iStoreContactField->CreateLinkLC() |
|
350 |
|
351 iResults->AppendL( link ); |
|
352 } |
|
353 } |
|
354 |
|
355 // -------------------------------------------------------------------------- |
|
356 // CPbk2AssignAttributePhase::FinalizeL |
|
357 // -------------------------------------------------------------------------- |
|
358 // |
|
359 void CPbk2AssignAttributePhase::FinalizeL() |
|
360 { |
|
361 AppendResultL(); |
|
362 iObserver.NextPhase( *this ); |
|
363 } |
|
364 |
|
365 // -------------------------------------------------------------------------- |
|
366 // CPbk2AssignAttributePhase::AssignAttributeL |
|
367 // -------------------------------------------------------------------------- |
|
368 // |
|
369 void CPbk2AssignAttributePhase::AssignAttributeL() |
|
370 { |
|
371 RetrieveContactFieldL(); |
|
372 |
|
373 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
374 ( *iEikEnv->EikAppUi() ); |
|
375 |
|
376 delete iContactAttributeAssigner; |
|
377 iContactAttributeAssigner = NULL; |
|
378 iContactAttributeAssigner = |
|
379 Pbk2ContactAssignerFactory::CreateContactAttributeAssignerL |
|
380 ( *this, appUi.ApplicationServices().ContactManager(), |
|
381 iAttributeData, iRemoveAttribute ); |
|
382 |
|
383 iContactAttributeAssigner->AssignAttributeL( *iStoreContact, |
|
384 iStoreContactField, iAttributeData ); |
|
385 } |
|
386 |
|
387 // End of File |