|
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: Prepend command object. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2PrependCmd.h" |
|
21 |
|
22 // From Phonebook2 |
|
23 #include "CPbk2CallCmd.h" |
|
24 #include "CPbk2AiwInterestArray.h" |
|
25 #include <Pbk2UIControls.rsg> |
|
26 #include <CPbk2PrependDlg.h> |
|
27 #include <Pbk2Commands.hrh> |
|
28 #include <CPbk2ContactUiControlSubstitute.h> |
|
29 #include <CPbk2PresentationContact.h> |
|
30 #include <CPbk2FieldPropertyArray.h> |
|
31 #include <CPbk2PresentationContactFieldCollection.h> |
|
32 #include <CPbk2PresentationContactField.h> |
|
33 #include <MPbk2ApplicationServices.h> |
|
34 #include <MPbk2AppUi.h> |
|
35 |
|
36 // From VirtualPhonebook |
|
37 #include <MVPbkContactFieldTextData.h> |
|
38 #include <MVPbkContactStore.h> |
|
39 |
|
40 /// Unnamed namespace for local definitions |
|
41 namespace { |
|
42 |
|
43 // Definition for buffer size |
|
44 const TInt KBufferSize( 50 ); |
|
45 |
|
46 #ifdef _DEBUG |
|
47 |
|
48 enum TPanicCode |
|
49 { |
|
50 EMaxLengthOfEditorL_OOB = 1 |
|
51 }; |
|
52 |
|
53 void Panic( TPanicCode aPanic ) |
|
54 { |
|
55 _LIT( KPanicCat, "CPbk2PrependCmd" ); |
|
56 User::Panic( KPanicCat, aPanic ); |
|
57 } |
|
58 |
|
59 #endif // _DEBUG |
|
60 |
|
61 } /// namespace |
|
62 |
|
63 // -------------------------------------------------------------------------- |
|
64 // CPbk2PrependCmd::CPbk2PrependCmd |
|
65 // -------------------------------------------------------------------------- |
|
66 // |
|
67 CPbk2PrependCmd::CPbk2PrependCmd( |
|
68 TInt aMenuCommandId, |
|
69 MPbk2ContactUiControl& aUiControl, |
|
70 CAiwServiceHandler& aServiceHandler, |
|
71 CPbk2CallTypeSelector& aSelector, |
|
72 MVPbkStoreContact*& aStoreContact, |
|
73 CPbk2FieldPropertyArray& aFieldProperties) : |
|
74 iUiControl(&aUiControl), |
|
75 iServiceHandler(aServiceHandler), |
|
76 iSelector(aSelector), |
|
77 iMenuCommandId( aMenuCommandId), |
|
78 iStoreContact( aStoreContact ), |
|
79 iFieldProperties( aFieldProperties ) |
|
80 { |
|
81 } |
|
82 |
|
83 // -------------------------------------------------------------------------- |
|
84 // CPbk2PrependCmd::~CPbk2PrependCmd |
|
85 // -------------------------------------------------------------------------- |
|
86 // |
|
87 CPbk2PrependCmd::~CPbk2PrependCmd() |
|
88 { |
|
89 delete iUiControlSubstitute; |
|
90 delete iTempContact; |
|
91 } |
|
92 |
|
93 // -------------------------------------------------------------------------- |
|
94 // CPbk2PrependCmd::NewL |
|
95 // -------------------------------------------------------------------------- |
|
96 // |
|
97 CPbk2PrependCmd* CPbk2PrependCmd::NewL( |
|
98 TInt aMenuCommandId, |
|
99 MPbk2ContactUiControl& aUiControl, |
|
100 CAiwServiceHandler& aServiceHandler, |
|
101 CPbk2CallTypeSelector& aSelector, |
|
102 MVPbkStoreContact*& aStoreContact, |
|
103 CPbk2FieldPropertyArray& aFieldProperties) |
|
104 { |
|
105 CPbk2PrependCmd* self = |
|
106 new(ELeave) CPbk2PrependCmd( |
|
107 aMenuCommandId, aUiControl, |
|
108 aServiceHandler, aSelector, |
|
109 aStoreContact, |
|
110 aFieldProperties); |
|
111 |
|
112 CleanupStack::PushL(self); |
|
113 self->ConstructL(); |
|
114 CleanupStack::Pop(self); |
|
115 return self; |
|
116 } |
|
117 |
|
118 // -------------------------------------------------------------------------- |
|
119 // CPbk2PrependCmd::ConstructL |
|
120 // -------------------------------------------------------------------------- |
|
121 // |
|
122 void CPbk2PrependCmd::ConstructL() |
|
123 { |
|
124 iUiControlSubstitute = CPbk2ContactUiControlSubstitute::NewL(); |
|
125 } |
|
126 |
|
127 // -------------------------------------------------------------------------- |
|
128 // CPbk2PrependCmd::ExecuteLD |
|
129 // -------------------------------------------------------------------------- |
|
130 // |
|
131 void CPbk2PrependCmd::ExecuteLD() |
|
132 { |
|
133 CleanupStack::PushL( this ); |
|
134 |
|
135 ExecuteDlgL(); |
|
136 |
|
137 CleanupStack::PopAndDestroy( this ); |
|
138 } |
|
139 |
|
140 // -------------------------------------------------------------------------- |
|
141 // CPbk2PrependCmd::ResetUiControl |
|
142 // -------------------------------------------------------------------------- |
|
143 // |
|
144 void CPbk2PrependCmd::ResetUiControl( |
|
145 MPbk2ContactUiControl& aUiControl) |
|
146 { |
|
147 if (iUiControl == &aUiControl) |
|
148 { |
|
149 iUiControl = NULL; |
|
150 } |
|
151 } |
|
152 |
|
153 // -------------------------------------------------------------------------- |
|
154 // CPbk2PrependCmd::AddObserver |
|
155 // -------------------------------------------------------------------------- |
|
156 // |
|
157 void CPbk2PrependCmd::AddObserver( MPbk2CommandObserver& /*aObserver*/ ) |
|
158 { |
|
159 // Do nothing |
|
160 } |
|
161 |
|
162 // -------------------------------------------------------------------------- |
|
163 // CPbk2PrependCmd::ExecuteDlgL |
|
164 // -------------------------------------------------------------------------- |
|
165 // |
|
166 void CPbk2PrependCmd::ExecuteDlgL() |
|
167 { |
|
168 if (iStoreContact && iUiControl) |
|
169 { |
|
170 // get field text (phone no) |
|
171 TInt fieldIndex( iUiControl->FocusedFieldIndex() ); |
|
172 MVPbkStoreContactField* field = |
|
173 iStoreContact->Fields().FieldAtLC( |
|
174 ToStoreFieldIndexL( fieldIndex ) ); |
|
175 TPtrC phoneNo = |
|
176 MVPbkContactFieldTextData::Cast( field->FieldData() ).Text(); |
|
177 HBufC* number = HBufC::NewLC( KBufferSize ); |
|
178 number->Des().Copy( phoneNo ); |
|
179 TPtr numberPtr = number->Des(); |
|
180 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( numberPtr ); |
|
181 // show dialog with that no |
|
182 CPbk2PrependDlg* dlg = CPbk2PrependDlg::NewL( numberPtr ); |
|
183 CleanupStack::PushL( dlg ); |
|
184 TInt maxLength( MaxLengthOfEditorL( fieldIndex ) ); |
|
185 CleanupStack::Pop( dlg ); |
|
186 if ( maxLength != KErrNotFound ) |
|
187 { |
|
188 // The length of prepend dialog's editor should be same as |
|
189 // field's maxlength. If maxLength is KErrNotFound use resource's |
|
190 // length. |
|
191 dlg->SetMaxLength( maxLength ); |
|
192 } |
|
193 // Get the contact store and field type from the iStoreContact before the prepend dialog is poped up, |
|
194 // since it might be changed When the dialog is poped up. |
|
195 MVPbkContactStore& store = iStoreContact->ParentStore(); |
|
196 const MVPbkFieldType* fieldType = field->BestMatchingFieldType(); |
|
197 if ( dlg->ExecuteLD(R_PBK2_PREPEND_QUERY) ) |
|
198 { |
|
199 // Create temporary contact for phone call |
|
200 delete iTempContact; |
|
201 iTempContact = NULL; |
|
202 iTempContact = store.CreateNewContactLC(); |
|
203 CleanupStack::Pop(); // iTempContact |
|
204 if( fieldType ) |
|
205 { |
|
206 // User has pressed ok, execute call |
|
207 MVPbkStoreContactField* tempField = |
|
208 iTempContact->CreateFieldLC( *fieldType ); |
|
209 |
|
210 MVPbkContactFieldTextData::Cast( tempField->FieldData() ). |
|
211 SetTextL( numberPtr ); |
|
212 // Takes ownership |
|
213 TInt tempFieldIndex = iTempContact->AddFieldL( tempField ); |
|
214 CleanupStack::Pop(); // tempField |
|
215 tempField = NULL; |
|
216 tempField = iTempContact->Fields().FieldAtLC( |
|
217 tempFieldIndex ); |
|
218 CleanupStack::Pop(); // tempField |
|
219 |
|
220 iUiControlSubstitute->SetFocusedStoreContact( *iTempContact ); |
|
221 iUiControlSubstitute->SetFocusedField( *tempField ); |
|
222 iUiControlSubstitute->SetFocusedFieldIndex( tempFieldIndex ); |
|
223 |
|
224 // Create call command to execute phone call |
|
225 CPbk2CallCmd* cmd = CPbk2CallCmd::NewL( |
|
226 iTempContact, |
|
227 tempField, |
|
228 *iUiControlSubstitute, |
|
229 EPbk2CmdCall, |
|
230 iServiceHandler, |
|
231 iSelector ); |
|
232 |
|
233 cmd->ExecuteLD(); |
|
234 } |
|
235 |
|
236 iUiControl->UpdateAfterCommandExecution(); |
|
237 } |
|
238 CleanupStack::PopAndDestroy( 2 ); // field, number |
|
239 } |
|
240 } |
|
241 |
|
242 // -------------------------------------------------------------------------- |
|
243 // CPbk2PrependCmd::ToStoreFieldIndexL |
|
244 // -------------------------------------------------------------------------- |
|
245 // |
|
246 TInt CPbk2PrependCmd::ToStoreFieldIndexL |
|
247 ( TInt aPresIndex ) |
|
248 { |
|
249 TInt index( KErrNotFound ); |
|
250 CPbk2PresentationContact* presentationContact = |
|
251 CreatePresentationContactLC(); |
|
252 index = presentationContact->PresentationFields().StoreIndexOfField |
|
253 ( aPresIndex ); |
|
254 |
|
255 CleanupStack::PopAndDestroy( presentationContact ); |
|
256 |
|
257 return index; |
|
258 } |
|
259 |
|
260 // -------------------------------------------------------------------------- |
|
261 // CPbk2PrependCmd::MaxLengthOfEditorL |
|
262 // -------------------------------------------------------------------------- |
|
263 // |
|
264 TInt CPbk2PrependCmd::MaxLengthOfEditorL( TInt aFieldIndex ) |
|
265 { |
|
266 TInt maxLength( KErrNotFound ); |
|
267 CPbk2PresentationContact* presentationContact = |
|
268 CreatePresentationContactLC(); |
|
269 |
|
270 __ASSERT_DEBUG( presentationContact->PresentationFields().FieldCount() > |
|
271 aFieldIndex, Panic( EMaxLengthOfEditorL_OOB ) ); |
|
272 |
|
273 maxLength = presentationContact->PresentationFields().At( aFieldIndex ). |
|
274 MaxDataLength(); |
|
275 |
|
276 CleanupStack::PopAndDestroy( presentationContact ); |
|
277 |
|
278 return maxLength; |
|
279 } |
|
280 |
|
281 // -------------------------------------------------------------------------- |
|
282 // CPbk2PrependCmd::CreatePresenationContactLC |
|
283 // -------------------------------------------------------------------------- |
|
284 // |
|
285 CPbk2PresentationContact* CPbk2PrependCmd::CreatePresentationContactLC() |
|
286 { |
|
287 CPbk2PresentationContact* presentationContact = |
|
288 CPbk2PresentationContact::NewL(*iStoreContact, iFieldProperties); |
|
289 CleanupStack::PushL( presentationContact ); |
|
290 return presentationContact; |
|
291 } |
|
292 |
|
293 // End of File |