author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:54:53 +0300 | |
branch | RCL_3 |
changeset 21 | 9da50d567e3c |
parent 20 | f4a778e096c2 |
permissions | -rw-r--r-- |
20 | 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" |
|
21
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
25 |
#include <pbk2uicontrols.rsg> |
20 | 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( fieldIndex ); |
|
174 |
TPtrC phoneNo = |
|
175 |
MVPbkContactFieldTextData::Cast( field->FieldData() ).Text(); |
|
176 |
HBufC* number = HBufC::NewLC( KBufferSize ); |
|
177 |
number->Des().Copy( phoneNo ); |
|
178 |
TPtr numberPtr = number->Des(); |
|
179 |
AknTextUtils::DisplayTextLanguageSpecificNumberConversion( numberPtr ); |
|
180 |
// show dialog with that no |
|
181 |
CPbk2PrependDlg* dlg = CPbk2PrependDlg::NewL( numberPtr ); |
|
182 |
CleanupStack::PushL( dlg ); |
|
183 |
TInt maxLength( MaxLengthOfEditorL( fieldIndex ) ); |
|
184 |
CleanupStack::Pop( dlg ); |
|
185 |
if ( maxLength != KErrNotFound ) |
|
186 |
{ |
|
187 |
// The length of prepend dialog's editor should be same as |
|
188 |
// field's maxlength. If maxLength is KErrNotFound use resource's |
|
189 |
// length. |
|
190 |
dlg->SetMaxLength( maxLength ); |
|
191 |
} |
|
192 |
// Get the contact store and field type from the iStoreContact before the prepend dialog is poped up, |
|
193 |
// since it might be changed When the dialog is poped up. |
|
194 |
MVPbkContactStore& store = iStoreContact->ParentStore(); |
|
195 |
const MVPbkFieldType* fieldType = field->BestMatchingFieldType(); |
|
196 |
if ( dlg->ExecuteLD(R_PBK2_PREPEND_QUERY) ) |
|
197 |
{ |
|
198 |
// Create temporary contact for phone call |
|
199 |
delete iTempContact; |
|
200 |
iTempContact = NULL; |
|
201 |
iTempContact = store.CreateNewContactLC(); |
|
202 |
CleanupStack::Pop(); // iTempContact |
|
203 |
if( fieldType ) |
|
204 |
{ |
|
205 |
// User has pressed ok, execute call |
|
206 |
MVPbkStoreContactField* tempField = |
|
207 |
iTempContact->CreateFieldLC( *fieldType ); |
|
208 |
||
209 |
MVPbkContactFieldTextData::Cast( tempField->FieldData() ). |
|
210 |
SetTextL( numberPtr ); |
|
211 |
// Takes ownership |
|
212 |
TInt tempFieldIndex = iTempContact->AddFieldL( tempField ); |
|
213 |
CleanupStack::Pop(); // tempField |
|
214 |
tempField = NULL; |
|
215 |
tempField = iTempContact->Fields().FieldAtLC( |
|
216 |
tempFieldIndex ); |
|
217 |
CleanupStack::Pop(); // tempField |
|
218 |
||
219 |
iUiControlSubstitute->SetFocusedStoreContact( *iTempContact ); |
|
220 |
iUiControlSubstitute->SetFocusedField( *tempField ); |
|
221 |
iUiControlSubstitute->SetFocusedFieldIndex( tempFieldIndex ); |
|
222 |
||
223 |
// Create call command to execute phone call |
|
224 |
CPbk2CallCmd* cmd = CPbk2CallCmd::NewL( |
|
225 |
iTempContact, |
|
226 |
tempField, |
|
227 |
*iUiControlSubstitute, |
|
228 |
EPbk2CmdCall, |
|
229 |
iServiceHandler, |
|
230 |
iSelector ); |
|
231 |
||
232 |
cmd->ExecuteLD(); |
|
233 |
} |
|
234 |
||
235 |
iUiControl->UpdateAfterCommandExecution(); |
|
236 |
} |
|
237 |
CleanupStack::PopAndDestroy( 2 ); // field, number |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
// -------------------------------------------------------------------------- |
|
242 |
// CPbk2PrependCmd::ToStoreFieldIndexL |
|
243 |
// -------------------------------------------------------------------------- |
|
244 |
// |
|
245 |
TInt CPbk2PrependCmd::ToStoreFieldIndexL |
|
246 |
( TInt aPresIndex ) |
|
247 |
{ |
|
248 |
TInt index( KErrNotFound ); |
|
249 |
CPbk2PresentationContact* presentationContact = |
|
250 |
CreatePresentationContactLC(); |
|
251 |
index = presentationContact->PresentationFields().StoreIndexOfField |
|
252 |
( aPresIndex ); |
|
253 |
||
254 |
CleanupStack::PopAndDestroy( presentationContact ); |
|
255 |
||
256 |
return index; |
|
257 |
} |
|
258 |
||
259 |
// -------------------------------------------------------------------------- |
|
260 |
// CPbk2PrependCmd::MaxLengthOfEditorL |
|
261 |
// -------------------------------------------------------------------------- |
|
262 |
// |
|
263 |
TInt CPbk2PrependCmd::MaxLengthOfEditorL( TInt aFieldStoreIndex ) |
|
264 |
{ |
|
265 |
TInt maxLength( KErrNotFound ); |
|
266 |
CPbk2PresentationContact* presentationContact = |
|
267 |
CreatePresentationContactLC(); |
|
268 |
||
269 |
TInt fieldIndex = KErrNotFound; |
|
270 |
||
271 |
fieldIndex = presentationContact->PresentationFields().FieldIndexOfStoreField( aFieldStoreIndex ); |
|
272 |
||
273 |
__ASSERT_DEBUG( presentationContact->PresentationFields().FieldCount() > |
|
274 |
fieldIndex, Panic( EMaxLengthOfEditorL_OOB ) ); |
|
275 |
||
276 |
__ASSERT_DEBUG( fieldIndex > KErrNotFound, Panic( EMaxLengthOfEditorL_OOB ) ); |
|
277 |
||
278 |
maxLength = presentationContact->PresentationFields().At( fieldIndex ). |
|
279 |
MaxDataLength(); |
|
280 |
||
281 |
CleanupStack::PopAndDestroy( presentationContact ); |
|
282 |
||
283 |
return maxLength; |
|
284 |
} |
|
285 |
||
286 |
// -------------------------------------------------------------------------- |
|
287 |
// CPbk2PrependCmd::CreatePresenationContactLC |
|
288 |
// -------------------------------------------------------------------------- |
|
289 |
// |
|
290 |
CPbk2PresentationContact* CPbk2PrependCmd::CreatePresentationContactLC() |
|
291 |
{ |
|
292 |
CPbk2PresentationContact* presentationContact = |
|
293 |
CPbk2PresentationContact::NewL(*iStoreContact, iFieldProperties); |
|
294 |
CleanupStack::PushL( presentationContact ); |
|
295 |
return presentationContact; |
|
296 |
} |
|
297 |
||
298 |
// End of File |