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) 2008 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 contact editor iamge field. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "CPbk2ContactEditorImageField.h" |
|
20 |
||
21 |
// Phonebook 2 |
|
22 |
#include "MPbk2ContactEditorUiBuilder.h" |
|
23 |
#include "MPbk2ContactEditorUiBuilderExtension.h" |
|
24 |
#include "MPbk2ContactEditorFieldVisitor.h" |
|
25 |
#include <MPbk2FieldProperty.h> |
|
26 |
#include <CPbk2PresentationContactField.h> |
|
27 |
#include <Pbk2PresentationUtils.h> |
|
28 |
#include "Pbk2ImageCommands.h" |
|
29 |
#include "CPbk2ContactEditorReadonlyField.h" |
|
30 |
#include "Pbk2EditorLineIds.hrh" |
|
31 |
#include <Pbk2UIControls.hrh> |
|
32 |
#include <Pbk2Config.hrh> |
|
33 |
||
34 |
// Virtual Phonebook |
|
35 |
#include <MVPbkContactFieldTextData.h> |
|
36 |
#include <VPbkFieldType.hrh> |
|
37 |
#include <MVPbkFieldType.h> |
|
21
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
38 |
#include <pbk2uicontrols.rsg> |
20 | 39 |
|
40 |
// System includes |
|
41 |
#include <eikcapc.h> |
|
42 |
#include <eikedwin.h> |
|
43 |
#include <AknUtils.h> |
|
44 |
||
45 |
// -------------------------------------------------------------------------- |
|
46 |
// CPbk2ContactEditorImageField::CPbk2ContactEditorImageField |
|
47 |
// -------------------------------------------------------------------------- |
|
48 |
// |
|
49 |
CPbk2ContactEditorImageField::CPbk2ContactEditorImageField |
|
50 |
( CPbk2PresentationContactField& aContactField, |
|
51 |
MPbk2ContactEditorUiBuilder& aUiBuilder, |
|
52 |
CPbk2IconInfoContainer& aIconInfoContainer ) : |
|
53 |
CPbk2ContactEditorFieldBase( aContactField, aUiBuilder, |
|
54 |
aIconInfoContainer ) |
|
55 |
{ |
|
56 |
} |
|
57 |
||
58 |
// -------------------------------------------------------------------------- |
|
59 |
// CPbk2ContactEditorImageField::~CPbk2ContactEditorImageField |
|
60 |
// -------------------------------------------------------------------------- |
|
61 |
// |
|
62 |
CPbk2ContactEditorImageField::~CPbk2ContactEditorImageField() |
|
63 |
{ |
|
64 |
delete iInitialText; |
|
65 |
} |
|
66 |
||
67 |
// -------------------------------------------------------------------------- |
|
68 |
// CPbk2ContactEditorImageField::NewLC |
|
69 |
// -------------------------------------------------------------------------- |
|
70 |
// |
|
71 |
CPbk2ContactEditorImageField* CPbk2ContactEditorImageField::NewLC |
|
72 |
( CPbk2PresentationContactField& aContactField, |
|
73 |
MPbk2ContactEditorUiBuilder& aUiBuilder, |
|
74 |
CPbk2IconInfoContainer& aIconInfoContainer, |
|
75 |
TInt aCustomPosition) |
|
76 |
{ |
|
77 |
CPbk2ContactEditorImageField* self = |
|
78 |
new ( ELeave ) CPbk2ContactEditorImageField( aContactField, |
|
79 |
aUiBuilder, aIconInfoContainer ); |
|
80 |
CleanupStack::PushL( self ); |
|
81 |
self->ConstructL(aCustomPosition); |
|
82 |
return self; |
|
83 |
} |
|
84 |
||
85 |
// -------------------------------------------------------------------------- |
|
86 |
// CPbk2ContactEditorImageField::ConstructL |
|
87 |
// Create and insert a line in the dialog |
|
88 |
// -------------------------------------------------------------------------- |
|
89 |
// |
|
90 |
void CPbk2ContactEditorImageField::ConstructL(TInt aCustomPosition) |
|
91 |
{ |
|
92 |
MPbk2ContactEditorUiBuilderExtension* ext = |
|
93 |
static_cast<MPbk2ContactEditorUiBuilderExtension*>( |
|
94 |
iUiBuilder.ContactEditorUiBuilderExtension(KNullUid)); |
|
95 |
||
96 |
iControl = static_cast<CPbk2ContactEditorReadonlyField*>( |
|
97 |
ext->AddCustomFieldToFormL(aCustomPosition, R_PBK2_IMAGE_LINE)); |
|
98 |
iControl->InitializeL(this); |
|
99 |
SetTextL(); |
|
100 |
iInitialText = iControl->GetTextInHBufL(); |
|
101 |
iControl->CreateTextViewL(); |
|
102 |
iCaptionedCtrl = iUiBuilder.LineControl(ControlId()); |
|
103 |
iUiBuilder.TryChangeFocusL(ControlId()); |
|
104 |
} |
|
105 |
||
106 |
// -------------------------------------------------------------------------- |
|
107 |
// CPbk2ContactEditorImageField::ControlId |
|
108 |
// -------------------------------------------------------------------------- |
|
109 |
// |
|
110 |
TInt CPbk2ContactEditorImageField::ControlId() const |
|
111 |
{ |
|
112 |
return EPbk2EditorLineImage; |
|
113 |
} |
|
114 |
||
115 |
// -------------------------------------------------------------------------- |
|
116 |
// CPbk2ContactEditorImageField::SetTextL |
|
117 |
// -------------------------------------------------------------------------- |
|
118 |
// |
|
119 |
void CPbk2ContactEditorImageField::SetTextL() |
|
120 |
{ |
|
121 |
// Get image name or set descriptive text |
|
122 |
TBool isFilename(EFalse); |
|
123 |
TVPbkFieldStorageType type = iContactField.FieldData().DataType(); |
|
124 |
||
125 |
if(type == EVPbkFieldStorageTypeText) |
|
126 |
{ |
|
127 |
isFilename = !iContactField.FieldData().IsEmpty(); |
|
128 |
} |
|
129 |
||
130 |
TBool isThumbnail(Pbk2ImageCommands::IsThumbnailFieldL(iContactField)); |
|
131 |
TBool imagefileValid(Pbk2ImageCommands::IsImageFieldValidL(iContactField)); |
|
132 |
||
133 |
if( !isFilename && !isThumbnail ) |
|
134 |
{ |
|
135 |
HBufC* defaultText = CCoeEnv::Static()->AllocReadResourceLC |
|
136 |
( R_QTN_PHOB_FIELD_ADD_IMAGE ); |
|
137 |
TPtrC dataPtr(*defaultText); |
|
138 |
||
139 |
FormatTextL( dataPtr, EDontClipFileExtension ); |
|
140 |
CleanupStack::PopAndDestroy(defaultText); |
|
141 |
iTextState = ENoData; |
|
142 |
} |
|
143 |
else if( !imagefileValid ) |
|
144 |
{ |
|
145 |
//cold filename, show "Thumbnail" (e.g mem card not present) |
|
146 |
HBufC* defaultText = CCoeEnv::Static()->AllocReadResourceLC |
|
147 |
( R_QTN_PHOB_FIELD_THUMBNAIL ); |
|
148 |
TPtrC dataPtr(*defaultText); |
|
149 |
||
150 |
FormatTextL( dataPtr, EClipFileExtension ); |
|
151 |
CleanupStack::PopAndDestroy(defaultText); |
|
152 |
iTextState = EThumbnail; |
|
153 |
} |
|
154 |
else |
|
155 |
{ |
|
156 |
TPtrC dataPtr(MVPbkContactFieldTextData::Cast( |
|
157 |
iContactField.FieldData()).Text()); |
|
158 |
||
159 |
FormatTextL( dataPtr, EClipFileExtension ); |
|
160 |
iTextState = EFilename; |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
// -------------------------------------------------------------------------- |
|
165 |
// CPbk2ContactEditorImageField::FormatTextL |
|
166 |
// -------------------------------------------------------------------------- |
|
167 |
// |
|
168 |
void CPbk2ContactEditorImageField::FormatTextL(TPtrC aDataPtr, TClipFileExtension aClipFileExtension) |
|
169 |
{ |
|
170 |
HBufC* textBuf = HBufC::NewLC(aDataPtr.Length()); |
|
171 |
TPtr text = textBuf->Des(); |
|
172 |
text.Zero(); |
|
173 |
Pbk2PresentationUtils::AppendWithNewlineTranslationL(text, aDataPtr); |
|
174 |
||
175 |
if (aClipFileExtension == EClipFileExtension ) |
|
176 |
{ |
|
177 |
TParsePtr fileNameParser( text ); |
|
178 |
TPtrC baseName( fileNameParser.Name() ); |
|
179 |
// Set formatted text to editor control |
|
180 |
iControl->SetTextL(&baseName); |
|
181 |
} |
|
182 |
else |
|
183 |
{ |
|
184 |
// Don't use filename parsing if a default string "Add image" is used. |
|
185 |
// There might be a dot in the end of the string and it would be then removed. |
|
186 |
// Example: "Adaug. imag." |
|
187 |
iControl->SetTextL(&text); |
|
188 |
} |
|
189 |
||
190 |
// SetTextL method above copied the text to the control, |
|
191 |
// so it is safe to destroy the buffer |
|
192 |
CleanupStack::PopAndDestroy(textBuf); |
|
193 |
iUiBuilder.LoadBitmapToFieldL |
|
194 |
( iContactField.FieldProperty(), iIconInfoContainer, ControlId() ); |
|
195 |
||
196 |
} |
|
197 |
||
198 |
// -------------------------------------------------------------------------- |
|
199 |
// CPbk2ContactEditorImageField::Control |
|
200 |
// -------------------------------------------------------------------------- |
|
201 |
// |
|
202 |
CEikEdwin* CPbk2ContactEditorImageField::Control() const |
|
203 |
{ |
|
204 |
// We don't show anything out |
|
205 |
return NULL; |
|
206 |
} |
|
207 |
||
208 |
// ----------------------------------------------------------------------------- |
|
209 |
// CPbk2ContactEditorImageField::ControlTextL |
|
210 |
// ----------------------------------------------------------------------------- |
|
211 |
// |
|
212 |
HBufC* CPbk2ContactEditorImageField::ControlTextL() const |
|
213 |
{ |
|
214 |
return CPbk2ContactEditorFieldBase::ControlTextL(); |
|
215 |
} |
|
216 |
||
217 |
// -------------------------------------------------------------------------- |
|
218 |
// CPbk2ContactEditorImageField::SaveFieldL |
|
219 |
// -------------------------------------------------------------------------- |
|
220 |
// |
|
221 |
void CPbk2ContactEditorImageField::SaveFieldL() |
|
222 |
{ |
|
223 |
HBufC* text = iControl->GetTextInHBufL(); |
|
224 |
CleanupStack::PushL(text); |
|
225 |
||
226 |
if(iInitialText->Compare(*text) ) |
|
227 |
{ |
|
228 |
iContactDataHasChanged = ETrue; |
|
229 |
} |
|
230 |
else |
|
231 |
{ |
|
232 |
iContactDataHasChanged = EFalse; |
|
233 |
} |
|
234 |
||
235 |
CleanupStack::PopAndDestroy(text); |
|
236 |
} |
|
237 |
||
238 |
// ----------------------------------------------------------------------------- |
|
239 |
// CPbk2ContactEditorImageField::HandleCustomFieldCommandL |
|
240 |
// ----------------------------------------------------------------------------- |
|
241 |
// |
|
242 |
TBool CPbk2ContactEditorImageField::HandleCustomFieldCommandL(TInt aCommand ) |
|
243 |
{ |
|
244 |
TBool ret(EFalse); |
|
245 |
MPbk2ContactEditorUiBuilderExtension* ext = |
|
246 |
static_cast<MPbk2ContactEditorUiBuilderExtension*>( |
|
247 |
iUiBuilder.ContactEditorUiBuilderExtension(KNullUid)); |
|
248 |
||
249 |
if(aCommand == EPbk2CmdEditorHandleCustomSelect) |
|
250 |
{ |
|
251 |
#ifdef ECE_DISABLE_CONTEXT_MENU |
|
252 |
if (ContactField().FieldData().IsEmpty()) |
|
253 |
{ |
|
254 |
ret = ext->HandleCustomFieldCommandL(EPbk2CmdEditorChangeImage); |
|
255 |
} |
|
256 |
else |
|
257 |
{ |
|
258 |
ret = ext->HandleCustomFieldCommandL(EPbk2CmdEditorContextMenu); |
|
259 |
} |
|
260 |
#else |
|
261 |
ret = ext->HandleCustomFieldCommandL(EPbk2CmdEditorChangeImage); |
|
262 |
#endif |
|
263 |
} |
|
264 |
else if(aCommand == EPbk2CmdEditorHandleCustomRemove) |
|
265 |
{ |
|
266 |
ret = ext->HandleCustomFieldCommandL(EPbk2CmdEditorRemoveImage); |
|
267 |
} |
|
268 |
return ret; |
|
269 |
} |
|
270 |
||
271 |
// -------------------------------------------------------------------------- |
|
272 |
// CPbk2ContactEditorImageField::ActivateL |
|
273 |
// -------------------------------------------------------------------------- |
|
274 |
// |
|
275 |
void CPbk2ContactEditorImageField::ActivateL() |
|
276 |
{ |
|
277 |
iCaptionedCtrl->ActivateL(); |
|
278 |
} |
|
279 |
||
280 |
// -------------------------------------------------------------------------- |
|
281 |
// CPbk2ContactEditorImageField::AcceptL |
|
282 |
// -------------------------------------------------------------------------- |
|
283 |
// |
|
284 |
void CPbk2ContactEditorImageField::AcceptL |
|
285 |
( MPbk2ContactEditorFieldVisitor& aVisitor ) |
|
286 |
{ |
|
287 |
aVisitor.VisitL( *this ); |
|
288 |
} |
|
289 |
||
290 |
// ----------------------------------------------------------------------------- |
|
291 |
// CPbk2ContactEditorImageField::ConsumesKeyEvent |
|
292 |
// ----------------------------------------------------------------------------- |
|
293 |
// |
|
294 |
TBool CPbk2ContactEditorImageField::ConsumesKeyEvent |
|
295 |
( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
296 |
{ |
|
297 |
||
298 |
TKeyResponse keyResponse = iControl->OfferKeyEventL( aKeyEvent, aType ); |
|
299 |
||
300 |
if ( EKeyWasConsumed == keyResponse ) |
|
301 |
{ |
|
302 |
return ETrue; |
|
303 |
} |
|
304 |
||
305 |
return EFalse; |
|
306 |
} |
|
307 |
||
308 |
// ----------------------------------------------------------------------------- |
|
309 |
// CPbk2ContactEditorImageField::TextState |
|
310 |
// ----------------------------------------------------------------------------- |
|
311 |
// |
|
312 |
TInt CPbk2ContactEditorImageField::TextState() |
|
313 |
{ |
|
314 |
return iTextState; |
|
315 |
} |
|
316 |
||
317 |
// ----------------------------------------------------------------------------- |
|
318 |
// CPbk2ContactEditorImageField::ContactField |
|
319 |
// ----------------------------------------------------------------------------- |
|
320 |
// |
|
321 |
CPbk2PresentationContactField& CPbk2ContactEditorImageField::ContactField() |
|
322 |
{ |
|
323 |
return iContactField; |
|
324 |
} |
|
325 |
||
326 |
// ----------------------------------------------------------------------------- |
|
327 |
// CPbk2ContactEditorImageField::ContactEditorFieldExtension |
|
328 |
// ----------------------------------------------------------------------------- |
|
329 |
// |
|
330 |
TAny* CPbk2ContactEditorImageField::ContactEditorFieldExtension( |
|
331 |
TUid aExtensionUid ) |
|
332 |
{ |
|
333 |
if( aExtensionUid == KMPbk2ContactEditorFieldExtension2Uid ) |
|
334 |
{ |
|
335 |
return static_cast<MPbk2ContactEditorField2*>( this ); |
|
336 |
} |
|
337 |
||
338 |
return this; |
|
339 |
} |
|
340 |
||
341 |
||
342 |
||
343 |
// End of File |