|
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: A command for setting ringing tone. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2SetToneCmd.h" |
|
21 |
|
22 #include <MPbk2CommandObserver.h> |
|
23 #include <CVPbkContactManager.h> |
|
24 #include <MPbk2ContactUiControl.h> |
|
25 #include <TVPbkFieldTypeMapping.h> |
|
26 #include <MVPbkContactLinkArray.h> |
|
27 #include <MVPbkContactFieldTextData.h> |
|
28 #include <MVPbkStoreContactField.h> |
|
29 #include <MVPbkStoreContact.h> |
|
30 #include <CPbk2ContactRelocator.h> |
|
31 #include <TPbk2StoreContactAnalyzer.h> |
|
32 #include <MVPbkContactOperationBase.h> |
|
33 #include <CPbk2PresentationContact.h> |
|
34 #include <CPbk2FieldPropertyArray.h> |
|
35 #include <CPbk2PresentationContactFieldCollection.h> |
|
36 #include <CPbk2FieldFocusHelper.h> |
|
37 #include <MPbk2ApplicationServices.h> |
|
38 #include <MPbk2AppUi.h> |
|
39 #include "CPbk2RingingToneFetch.h" |
|
40 |
|
41 #include <Pbk2UIControls.rsg> |
|
42 #include <coemain.h> |
|
43 |
|
44 #include <Pbk2Debug.h> |
|
45 |
|
46 // ============================ LOCAL FUNCTIONS ============================= |
|
47 |
|
48 namespace |
|
49 { |
|
50 #ifdef _DEBUG |
|
51 enum TPanicCode |
|
52 { |
|
53 EPanicLogic_ReadFieldTypeL, |
|
54 EPanicLogic_ContactCommitCompelete, |
|
55 EPanicPreCond_RelocationProcessCompleteL |
|
56 }; |
|
57 |
|
58 void Panic(TInt aReason) |
|
59 { |
|
60 _LIT(KPanicText, "CPbk2SetToneCmd"); |
|
61 User::Panic(KPanicText, aReason); |
|
62 } |
|
63 #endif // _DEBUG |
|
64 } |
|
65 |
|
66 // ============================ MEMBER FUNCTIONS ============================ |
|
67 |
|
68 // -------------------------------------------------------------------------- |
|
69 // CPbk2SetToneCmd::CPbk2SetToneCmd |
|
70 // C++ default constructor can NOT contain any code, that |
|
71 // might leave. |
|
72 // -------------------------------------------------------------------------- |
|
73 // |
|
74 CPbk2SetToneCmd::CPbk2SetToneCmd( |
|
75 MPbk2ContactUiControl& aUiControl ) : |
|
76 CPbk2SetToneBase( aUiControl ) |
|
77 { |
|
78 // Do nothing |
|
79 } |
|
80 |
|
81 // -------------------------------------------------------------------------- |
|
82 // CPbk2SetToneCmd::~CPbk2SetToneCmd |
|
83 // -------------------------------------------------------------------------- |
|
84 // |
|
85 CPbk2SetToneCmd::~CPbk2SetToneCmd() |
|
86 { |
|
87 delete iFieldFocusHelper; |
|
88 iFieldFocusHelper = NULL; |
|
89 } |
|
90 |
|
91 // -------------------------------------------------------------------------- |
|
92 // CPbk2SetToneCmd::NewL |
|
93 // Two-phased constructor. |
|
94 // -------------------------------------------------------------------------- |
|
95 // |
|
96 CPbk2SetToneCmd* CPbk2SetToneCmd::NewL( |
|
97 MPbk2ContactUiControl& aUiControl) |
|
98 { |
|
99 CPbk2SetToneCmd* self = |
|
100 new( ELeave ) CPbk2SetToneCmd( aUiControl ); |
|
101 CleanupStack::PushL( self ); |
|
102 self->ConstructL(); |
|
103 CleanupStack::Pop( self ); |
|
104 return self; |
|
105 } |
|
106 |
|
107 // -------------------------------------------------------------------------- |
|
108 // CPbk2SetToneCmd::ConstructL |
|
109 // Symbian 2nd phase constructor can leave. |
|
110 // -------------------------------------------------------------------------- |
|
111 // |
|
112 void CPbk2SetToneCmd::ConstructL() |
|
113 { |
|
114 BaseConstructL(); |
|
115 iFieldFocusHelper = CPbk2FieldFocusHelper::NewL( |
|
116 *iUiControl, |
|
117 Phonebook2::Pbk2AppUi()->ApplicationServices().FieldProperties() ); |
|
118 } |
|
119 |
|
120 // -------------------------------------------------------------------------- |
|
121 // CPbk2SetToneCmd::ContactRelocatedL |
|
122 // -------------------------------------------------------------------------- |
|
123 // |
|
124 void CPbk2SetToneCmd::ContactRelocatedL( |
|
125 MVPbkStoreContact* aRelocatedContact) |
|
126 { |
|
127 // Takes ownership of the aRelocatedContact |
|
128 delete iStoreContact; |
|
129 iStoreContact = aRelocatedContact; |
|
130 } |
|
131 |
|
132 // -------------------------------------------------------------------------- |
|
133 // CPbk2SetToneCmd::ContactRelocationFailed |
|
134 // -------------------------------------------------------------------------- |
|
135 // |
|
136 void CPbk2SetToneCmd::ContactRelocationFailed( |
|
137 TInt aReason, MVPbkStoreContact* aContact) |
|
138 { |
|
139 // We got the ownership of aContact |
|
140 delete aContact; |
|
141 if ( aReason == KErrCancel ) |
|
142 { |
|
143 // No error note is to be shown to the user when she |
|
144 // manually cancels the relocation process, therefore |
|
145 // the error code must be converted |
|
146 aReason = KErrNone; |
|
147 } |
|
148 ProcessDismissed( aReason ); |
|
149 } |
|
150 |
|
151 // -------------------------------------------------------------------------- |
|
152 // CPbk2SetToneCmd::ContactRelocationFailed |
|
153 // -------------------------------------------------------------------------- |
|
154 // |
|
155 void CPbk2SetToneCmd::ContactsRelocationFailed( |
|
156 TInt /*aReason*/, CVPbkContactLinkArray* /*aContacts*/ ) |
|
157 { |
|
158 // Do nothing |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------- |
|
162 // CPbk2SetToneCmd::RelocationProcessComplete |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 void CPbk2SetToneCmd::RelocationProcessComplete() |
|
166 { |
|
167 __ASSERT_DEBUG( iStoreContact, |
|
168 Panic( EPanicPreCond_RelocationProcessCompleteL ) ); |
|
169 // Lock contact for setting tone |
|
170 TRAPD( res, iStoreContact->LockL( *this ) ); |
|
171 if ( res != KErrNone ) |
|
172 { |
|
173 ProcessDismissed( res ); |
|
174 } |
|
175 } |
|
176 |
|
177 // -------------------------------------------------------------------------- |
|
178 // CPbk2SetToneCmd::RelocationProcessCompleteL |
|
179 // -------------------------------------------------------------------------- |
|
180 // |
|
181 void CPbk2SetToneCmd::VPbkSingleContactOperationComplete( |
|
182 MVPbkContactOperationBase& /*aOperation*/, |
|
183 MVPbkStoreContact* aContact) |
|
184 { |
|
185 delete iRetrieveOperation; |
|
186 iRetrieveOperation = NULL; |
|
187 |
|
188 delete iStoreContact; |
|
189 iStoreContact = aContact; |
|
190 |
|
191 if ( !ContactHasRingToneField( iStoreContact ) && iToneFilename.Length() <=0 ) |
|
192 { |
|
193 // User has selected 'no personal ringtone' for contact which |
|
194 // does not have ring tone field, so we can quit now |
|
195 ProcessDismissed( KErrNone ); |
|
196 } |
|
197 else |
|
198 { |
|
199 TBool contactNeedsRelocation = EFalse; |
|
200 TInt err = KErrNone; |
|
201 TRAP( err, contactNeedsRelocation = |
|
202 RelocateContactL( iStoreContact ) ); |
|
203 |
|
204 if (err != KErrNone) |
|
205 { |
|
206 ProcessDismissed( err ); |
|
207 } |
|
208 |
|
209 if ( !contactNeedsRelocation ) |
|
210 { |
|
211 TRAP( err, iStoreContact->LockL( *this ) ); |
|
212 if ( err != KErrNone ) |
|
213 { |
|
214 ProcessDismissed( err ); |
|
215 } |
|
216 } |
|
217 else |
|
218 { |
|
219 // Relocator has taken the ownership of the contact |
|
220 iStoreContact = NULL; |
|
221 } |
|
222 } |
|
223 } |
|
224 |
|
225 // -------------------------------------------------------------------------- |
|
226 // CPbk2SetToneCmd::RelocationProcessCompleteL |
|
227 // -------------------------------------------------------------------------- |
|
228 // |
|
229 void CPbk2SetToneCmd::VPbkSingleContactOperationFailed( |
|
230 MVPbkContactOperationBase& /*aOperation*/, |
|
231 TInt aError ) |
|
232 { |
|
233 ProcessDismissed( aError ); |
|
234 } |
|
235 |
|
236 // -------------------------------------------------------------------------- |
|
237 // CPbk2SetToneCmd::RelocationProcessCompleteL |
|
238 // -------------------------------------------------------------------------- |
|
239 // |
|
240 void CPbk2SetToneCmd::ContactOperationCompleted( |
|
241 TContactOpResult aResult) |
|
242 { |
|
243 if ( aResult.iOpCode == EContactLock ) |
|
244 { |
|
245 // We have to save the initially focused field, so that we can put |
|
246 // it back focused after setting and committing ringingtone. |
|
247 // If leaves the focus will not be set. |
|
248 TRAP_IGNORE( iFieldFocusHelper->SaveInitiallyFocusedFieldL |
|
249 ( *iStoreContact ) ); |
|
250 TRAPD( err, SetToneAndCommitL( iStoreContact ) ); |
|
251 if ( err != KErrNone ) |
|
252 { |
|
253 CCoeEnv::Static()->HandleError( err ); |
|
254 ProcessDismissed( err ); |
|
255 } |
|
256 } |
|
257 else if ( aResult.iOpCode == EContactCommit ) |
|
258 { |
|
259 // Set the original field focused after command execution |
|
260 TRAP_IGNORE( iFieldFocusHelper->RestoreSavedFieldL() ); |
|
261 // Now, its time to exit the command |
|
262 IssueStopRequest(); |
|
263 } |
|
264 } |
|
265 |
|
266 // -------------------------------------------------------------------------- |
|
267 // CPbk2SetToneCmd::RelocationProcessCompleteL |
|
268 // -------------------------------------------------------------------------- |
|
269 // |
|
270 void CPbk2SetToneCmd::ContactOperationFailed( |
|
271 TContactOp /*aOpCode*/, |
|
272 TInt aErrorCode, |
|
273 TBool /*aErrorNotified*/) |
|
274 { |
|
275 if ( aErrorCode != KErrNone ) |
|
276 { |
|
277 CCoeEnv::Static()->HandleError( aErrorCode ); |
|
278 } |
|
279 |
|
280 ProcessDismissed( aErrorCode ); |
|
281 } |
|
282 |
|
283 // -------------------------------------------------------------------------- |
|
284 // CPbk2SetToneCmd::ContactHasRingToneField |
|
285 // -------------------------------------------------------------------------- |
|
286 // |
|
287 inline TBool CPbk2SetToneCmd::ContactHasRingToneField( |
|
288 MVPbkStoreContact* aContact ) |
|
289 { |
|
290 TBool ret( ETrue ); |
|
291 |
|
292 TPbk2StoreContactAnalyzer analyzer |
|
293 ( Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(), |
|
294 aContact ); |
|
295 TInt fieldIndex( KErrNotFound ); |
|
296 // No harm done if field finding leaves |
|
297 // it just might produce unnecessary relocation note but nothing more |
|
298 TRAP_IGNORE( fieldIndex = analyzer.HasFieldL( R_PHONEBOOK2_RINGTONE_SELECTOR ) ); |
|
299 if ( fieldIndex == KErrNotFound ) |
|
300 { |
|
301 ret = EFalse; |
|
302 } |
|
303 |
|
304 return ret; |
|
305 } |
|
306 |
|
307 // End of File |