|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * Methods for Postcard Address form. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <eikspane.h> // CEikStatusPane |
|
24 #include <eikmenub.h> |
|
25 #include <eiklabel.h> // for CEikLabel |
|
26 |
|
27 #include <avkon.hrh> |
|
28 #include <aknnavi.h> // CAknNavigationControlContainer |
|
29 #include <aknnavide.h> // CAknNavigationDecorator |
|
30 #include <AknIndicatorContainer.h> // for CAknIndicatorContainer |
|
31 #include <aknEditStateIndicator.h> // for MAknEditStateIndicator |
|
32 #include <akntitle.h> |
|
33 #include <AknQueryDialog.h> |
|
34 #include <aknnotewrappers.h> |
|
35 #include <AknsUtils.h> |
|
36 #include <aknlists.h> |
|
37 |
|
38 #include <featmgr.h> |
|
39 #include <StringLoader.h> |
|
40 #include <csxhelp/postcard.hlp.hrh> |
|
41 |
|
42 #include <cntitem.h> |
|
43 #include <cntfldst.h> |
|
44 #include <mmsmsventry.h> |
|
45 |
|
46 #include <Postcard.rsg> |
|
47 #include "Postcard.hrh" |
|
48 #include "PostcardLaf.h" |
|
49 #include "PostcardDocument.h" |
|
50 #include "PostcardAppUi.h" |
|
51 #include "PostcardAddressForm.h" |
|
52 #include "PostcardUtils.h" |
|
53 #include "PostcardRecipientWrapper.h" |
|
54 |
|
55 // ================= MEMBER FUNCTIONS ======================= |
|
56 |
|
57 // --------------------------------------------------------- |
|
58 // Two-phased constructor |
|
59 // --------------------------------------------------------- |
|
60 CPostcardAddressForm* CPostcardAddressForm::NewL( CPostcardAppUi& aAppUi, CPostcardDocument& aDocument, CContactCard& aContactItem, TInt& aRetValue, TInt aFirstActive, TKeyEvent aKeyEvent ) |
|
61 { |
|
62 CPostcardAddressForm* self = |
|
63 new (ELeave) CPostcardAddressForm( aAppUi, aDocument, aContactItem, aRetValue, aFirstActive, aKeyEvent ); |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL( ); |
|
66 CleanupStack::Pop( ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------- |
|
71 // Default destructor |
|
72 // --------------------------------------------------------- |
|
73 CPostcardAddressForm::~CPostcardAddressForm() |
|
74 { |
|
75 delete iContact; |
|
76 |
|
77 // Remove the navidecorator from status pane |
|
78 CEikStatusPane *sp = iEikonEnv->AppUiFactory( )->StatusPane( ); |
|
79 TRAP_IGNORE( static_cast<CAknNavigationControlContainer*> |
|
80 ( sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) )->Pop( iNaviDecorator ); |
|
81 ); // TRAP_IGNORE |
|
82 delete iNaviDecorator; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------- |
|
86 // CPostcardAddressForm |
|
87 // --------------------------------------------------------- |
|
88 CPostcardAddressForm::CPostcardAddressForm |
|
89 ( CPostcardAppUi& aAppUi, |
|
90 CPostcardDocument& aDocument, |
|
91 CContactCard& aContactItem, |
|
92 TInt& aRetValue, |
|
93 TInt aFirstActive, |
|
94 TKeyEvent aKeyEvent ) : |
|
95 iContactItem( aContactItem ), |
|
96 iAppUi( aAppUi ), |
|
97 iDocument( aDocument ), |
|
98 iNaviDecorator( NULL ), |
|
99 iKeyEvent( aKeyEvent ), |
|
100 iRetValue( aRetValue ), |
|
101 iPreviousControl( NULL ), |
|
102 iFirstActive( aFirstActive ) |
|
103 { |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------- |
|
108 // ExecuteLD() |
|
109 // --------------------------------------------------------- |
|
110 TInt CPostcardAddressForm::ExecLD( ) |
|
111 { |
|
112 PrepareLC( R_POSTCARD_ADDRESS_DIALOG ); |
|
113 return CAknForm::RunLD( ); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------- |
|
117 // ConstructL |
|
118 // --------------------------------------------------------- |
|
119 void CPostcardAddressForm::ConstructL( ) |
|
120 { |
|
121 |
|
122 // Feature manager |
|
123 FeatureManager::InitializeLibL( ); |
|
124 |
|
125 if( FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
126 { |
|
127 iAddrFlags |= EPostcardAddressHelpSupported; |
|
128 } |
|
129 |
|
130 FeatureManager::UnInitializeLib( ); |
|
131 |
|
132 CleanNavipane(); |
|
133 |
|
134 // Call the base class' two-phased constructor |
|
135 CAknDialog::ConstructL( R_POSTCARD_ADDRESS_MENUBAR ); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------- |
|
139 // OfferKeyEventL |
|
140 // --------------------------------------------------------- |
|
141 TKeyResponse CPostcardAddressForm::OfferKeyEventL |
|
142 (const TKeyEvent& aKeyEvent, |
|
143 TEventCode aType) |
|
144 { |
|
145 // Only interested in standard key events |
|
146 if ( aType != EEventKey ) |
|
147 { |
|
148 return EKeyWasNotConsumed; |
|
149 } |
|
150 |
|
151 // If a menu is showing offer key events to it. |
|
152 if ( CAknForm::MenuShowing( ) ) |
|
153 { |
|
154 return CAknForm::OfferKeyEventL( aKeyEvent, aType ); |
|
155 } |
|
156 |
|
157 TUint code = aKeyEvent.iCode; |
|
158 |
|
159 TKeyResponse resp=EKeyWasNotConsumed; |
|
160 |
|
161 switch ( code ) |
|
162 { |
|
163 case EKeyOK: |
|
164 { |
|
165 DoSelectionKeyL( ); |
|
166 resp=EKeyWasConsumed; |
|
167 break; |
|
168 } |
|
169 |
|
170 case EKeyBackspace: |
|
171 case EKeyDelete: |
|
172 { |
|
173 resp = CAknForm::OfferKeyEventL( aKeyEvent, aType ); |
|
174 break; |
|
175 } |
|
176 |
|
177 case EKeyYes: |
|
178 { |
|
179 if( iDocument.MessageType( ) != EPostcardSent ) |
|
180 { // This is draft message |
|
181 if( IsEmpty( ) ) |
|
182 { |
|
183 DoAddRecipientL( ); |
|
184 } |
|
185 else |
|
186 { |
|
187 SendL(); |
|
188 } |
|
189 resp=EKeyWasConsumed; |
|
190 break; |
|
191 } |
|
192 // If message is sent -> intentionally let it fall thru |
|
193 } |
|
194 //lint -fallthrough |
|
195 case EKeyEscape: |
|
196 // Update recipient to entry |
|
197 UpdateRecipientToEntryL(); |
|
198 // Escape dismisses (destroys) the dialog |
|
199 return CAknForm::OfferKeyEventL( aKeyEvent, aType ); |
|
200 |
|
201 case EKeyApplication: |
|
202 case EKeyPhoneEnd: |
|
203 case EKeyPowerOff: |
|
204 case EKeyGripOpen: |
|
205 case EKeyGripClose: |
|
206 case EKeySide: |
|
207 default: |
|
208 resp=CAknForm::OfferKeyEventL( aKeyEvent, aType ); |
|
209 CheckTextExceedingL(); |
|
210 break; |
|
211 |
|
212 } |
|
213 |
|
214 return resp; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------- |
|
218 // UpdateRecipientToEntryL |
|
219 // --------------------------------------------------------- |
|
220 void CPostcardAddressForm::UpdateRecipientToEntryL() |
|
221 { |
|
222 if( iDocument.MessageType( ) != EPostcardSent ) |
|
223 { |
|
224 // Create an empty (ie. no fields) contact card |
|
225 CContactCard* card = CContactCard::NewLC(); |
|
226 |
|
227 for(TInt loop = EPostcardAddressName; loop<=EPostcardAddressCountry; loop++ ) |
|
228 { |
|
229 CEikEdwin* edwin = static_cast< CEikEdwin* >(ControlOrNull( loop ) ); |
|
230 if( edwin && edwin->TextLength( ) > 0 ) |
|
231 { // The field is not empty: lets add field with right label |
|
232 TPostcardUtils::AddContactFieldL( *card, |
|
233 TPostcardUtils::ContactItemNameFromId( loop ), |
|
234 edwin->Text()->Read( 0, edwin->TextLength() ) ); |
|
235 } |
|
236 } |
|
237 CleanupStack::Pop( card ); |
|
238 // Update AppUi's contact. |
|
239 iAppUi.SetRecipientL( *card ); |
|
240 // Recipient changed, so we can change field to modified. |
|
241 iDocument.SetChanged( EPostcardRecipient ); |
|
242 } |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------- |
|
246 // PreLayoutDynInitL |
|
247 // --------------------------------------------------------- |
|
248 void CPostcardAddressForm::PreLayoutDynInitL() |
|
249 { |
|
250 SetEditableL(ETrue); |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------- |
|
254 // PostLayoutDynInitL |
|
255 // --------------------------------------------------------- |
|
256 void CPostcardAddressForm::PostLayoutDynInitL() |
|
257 { |
|
258 |
|
259 // Read the mandatory fields |
|
260 TInt mandatories = iAppUi.MandatoryAddressFields( ); |
|
261 |
|
262 for(TInt loop = EPostcardAddressName; loop<=EPostcardAddressCountry; loop++ ) |
|
263 { |
|
264 CEikEdwin* edwin = static_cast< CEikEdwin* >(ControlOrNull( loop ) ); |
|
265 if( edwin ) |
|
266 { |
|
267 TInt max = iAppUi.MaxTextLength(loop); |
|
268 edwin->SetMaxLength( max ); |
|
269 if( max < 1 ) |
|
270 { // If max is less than 1 -> make it invisible |
|
271 DeleteLine( loop, ETrue ); |
|
272 } |
|
273 else |
|
274 { |
|
275 if( loop == EPostcardAddressZip ) |
|
276 { |
|
277 edwin->SetAknEditorInputMode( EAknEditorNumericInputMode ); |
|
278 } |
|
279 // Field is visible, let's see if it's mandatory too |
|
280 TInt bit = 1 << ( loop - EPostcardAddressName ); |
|
281 if ( bit & mandatories ) |
|
282 { // This control is mandatory so lets add asterisk |
|
283 CEikLabel* label = ControlCaption( loop ); |
|
284 HBufC* mandLabel = HBufC::NewLC( label->Text()->Length() + 2 ); |
|
285 TPtr labelPtr = mandLabel->Des( ); |
|
286 labelPtr.Zero( ); |
|
287 labelPtr.Append( _L("* ") ); |
|
288 labelPtr.Append( *label->Text( ) ); |
|
289 SetControlCaptionL( loop, *mandLabel ); |
|
290 CleanupStack::PopAndDestroy( mandLabel ); // mandLabel |
|
291 } |
|
292 } |
|
293 } |
|
294 } |
|
295 |
|
296 UpdateFieldsL( iContactItem ); |
|
297 |
|
298 if( iDocument.MessageType( ) == EPostcardSent ) |
|
299 { // Set all fields read-only |
|
300 for(TInt loop = EPostcardAddressName; loop<=EPostcardAddressCountry; loop++ ) |
|
301 { |
|
302 CEikEdwin* edwin = static_cast< CEikEdwin* >(ControlOrNull( loop ) ); |
|
303 if( edwin ) |
|
304 { |
|
305 edwin->AddFlagToUserFlags( CEikEdwin::EReadOnly ); |
|
306 edwin->AddFlagToUserFlags( CEikEdwin::EAvkonDisableCursor ); |
|
307 } |
|
308 } |
|
309 } |
|
310 |
|
311 SetInitialCurrentLine( ); |
|
312 SetEditableL(ETrue); |
|
313 |
|
314 SetMiddleSoftkeyL(); |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------- |
|
318 // SetInitialCurrentLine |
|
319 // --------------------------------------------------------- |
|
320 void CPostcardAddressForm::SetInitialCurrentLine() |
|
321 { |
|
322 // In case something else than Name field is focused |
|
323 // -> it means we have already been here so there's no need to call this again |
|
324 TInt focused = IdOfFocusControl( ); |
|
325 TInt a = EPostcardAddressName; |
|
326 if( focused == a ) |
|
327 { |
|
328 CAknForm::SetInitialCurrentLine(); |
|
329 } |
|
330 } |
|
331 |
|
332 // --------------------------------------------------------- |
|
333 // HandleResourceChange |
|
334 // --------------------------------------------------------- |
|
335 void CPostcardAddressForm::HandleResourceChange(TInt aType ) |
|
336 { |
|
337 CAknForm::HandleResourceChange( aType ); |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------- |
|
341 // CPostcardAddressDialog::ProcessCommandL |
|
342 // --------------------------------------------------------- |
|
343 void CPostcardAddressForm::ProcessCommandL( TInt aCommandId ) |
|
344 { |
|
345 HideMenu( ); |
|
346 |
|
347 switch ( aCommandId ) |
|
348 { |
|
349 case EPostcardCmdSend: |
|
350 SendL( ); |
|
351 break; |
|
352 |
|
353 case EPostcardCmdForward: |
|
354 ForwardMessageL( ); |
|
355 break; |
|
356 |
|
357 case EPostcardCmdMessageInfo: |
|
358 MessageInfoL( ); |
|
359 break; |
|
360 |
|
361 case EPostcardCmdAddRecipient: |
|
362 case EPostcardCmdReplaceRecipient: |
|
363 // These MSK commands are not active in viewer mode |
|
364 DoAddRecipientL( ); |
|
365 SetMiddleSoftkeyL(); |
|
366 break; |
|
367 |
|
368 case EMsgDispSizeAutomatic: |
|
369 case EMsgDispSizeLarge: |
|
370 case EMsgDispSizeNormal: |
|
371 case EMsgDispSizeSmall: |
|
372 iAppUi.HandleLocalZoomChangeL( (TMsgCommonCommands)aCommandId ); |
|
373 break; |
|
374 case EAknCmdHelp: |
|
375 LaunchHelpL( ); |
|
376 break; |
|
377 |
|
378 case EAknCmdExit: |
|
379 case EEikCmdExit: |
|
380 if( OkToExitL( aCommandId ) ) |
|
381 { |
|
382 iRetValue = EPostcardDialogExit; |
|
383 TryExitL( EAknSoftkeyDone ); |
|
384 } |
|
385 break; |
|
386 |
|
387 default : |
|
388 CAknForm::ProcessCommandL( aCommandId ); |
|
389 break; |
|
390 } |
|
391 } |
|
392 |
|
393 // --------------------------------------------------------- |
|
394 // DynInitMenuPaneL |
|
395 // --------------------------------------------------------- |
|
396 void CPostcardAddressForm::DynInitMenuPaneL |
|
397 (TInt aResourceId, |
|
398 CEikMenuPane* aMenuPane) |
|
399 { |
|
400 switch ( aResourceId ) |
|
401 { |
|
402 case R_POSTCARD_ADDRESS_OPTIONS: |
|
403 DynInitMainMenuL( aMenuPane ); |
|
404 break; |
|
405 case R_POSTCARD_ZOOM_SUBMENU: |
|
406 { |
|
407 TInt zoomLevel = KErrGeneral; |
|
408 iAppUi.GetZoomLevelL( zoomLevel ); |
|
409 switch ( zoomLevel ) |
|
410 { |
|
411 case EAknUiZoomAutomatic: |
|
412 aMenuPane->SetItemButtonState( EMsgDispSizeAutomatic, |
|
413 EEikMenuItemSymbolOn ); |
|
414 break; |
|
415 case EAknUiZoomNormal: |
|
416 aMenuPane->SetItemButtonState( EMsgDispSizeNormal, |
|
417 EEikMenuItemSymbolOn ); |
|
418 break; |
|
419 case EAknUiZoomSmall: |
|
420 aMenuPane->SetItemButtonState( EMsgDispSizeSmall, |
|
421 EEikMenuItemSymbolOn ); |
|
422 break; |
|
423 case EAknUiZoomLarge: |
|
424 aMenuPane->SetItemButtonState( EMsgDispSizeLarge, |
|
425 EEikMenuItemSymbolOn ); |
|
426 break; |
|
427 default: |
|
428 break; |
|
429 } |
|
430 } |
|
431 break; |
|
432 default: |
|
433 break; |
|
434 } |
|
435 } |
|
436 |
|
437 // --------------------------------------------------------- |
|
438 // DynInitMainMenuL |
|
439 // --------------------------------------------------------- |
|
440 void CPostcardAddressForm::DynInitMainMenuL( CEikMenuPane* aMenuPane ) |
|
441 { |
|
442 aMenuPane->SetItemDimmed( EPostcardCmdSend, |
|
443 IsMainMenuOptionInvisible( EPostcardCmdSend )); |
|
444 aMenuPane->SetItemDimmed( EPostcardCmdAddRecipient, |
|
445 IsMainMenuOptionInvisible( EPostcardCmdAddRecipient )); |
|
446 aMenuPane->SetItemDimmed( EPostcardCmdReplaceRecipient, |
|
447 IsMainMenuOptionInvisible( EPostcardCmdReplaceRecipient )); |
|
448 aMenuPane->SetItemDimmed( EPostcardCmdForward, |
|
449 IsMainMenuOptionInvisible( EPostcardCmdForward )); |
|
450 aMenuPane->SetItemDimmed( EPostcardCmdMessageInfo, |
|
451 IsMainMenuOptionInvisible( EPostcardCmdMessageInfo )); |
|
452 aMenuPane->SetItemDimmed( EAknCmdHelp, iAddrFlags & EPostcardAddressHelpSupported?EFalse:ETrue ); |
|
453 aMenuPane->SetItemDimmed( EAknCmdExit, EFalse ); |
|
454 } |
|
455 |
|
456 // --------------------------------------------------------- |
|
457 // IsMainMenuOptionInvisible |
|
458 // --------------------------------------------------------- |
|
459 TBool CPostcardAddressForm::IsMainMenuOptionInvisible( TInt aMenuOptionId ) |
|
460 { |
|
461 TBool retVal = ETrue; |
|
462 TPostcardMsgType msgType = iDocument.MessageType( ); |
|
463 |
|
464 switch ( aMenuOptionId ) |
|
465 { |
|
466 |
|
467 case EPostcardCmdSend: |
|
468 if( msgType != EPostcardSent ) |
|
469 { |
|
470 if( !IsEmpty( ) ) |
|
471 { |
|
472 retVal = EFalse; |
|
473 } |
|
474 } |
|
475 break; |
|
476 case EPostcardCmdAddRecipient: |
|
477 if( msgType != EPostcardSent ) |
|
478 { |
|
479 if( IsEmpty( ) ) |
|
480 { |
|
481 retVal = EFalse; |
|
482 } |
|
483 } |
|
484 break; |
|
485 case EPostcardCmdReplaceRecipient: |
|
486 if( msgType != EPostcardSent ) |
|
487 { |
|
488 if( !IsEmpty( ) ) |
|
489 { |
|
490 retVal = EFalse; |
|
491 } |
|
492 } |
|
493 break; |
|
494 case EPostcardCmdForward: |
|
495 if( msgType == EPostcardSent ) |
|
496 { |
|
497 retVal = EFalse; |
|
498 } |
|
499 break; |
|
500 case EPostcardCmdMessageInfo: |
|
501 { |
|
502 retVal = EFalse; |
|
503 break; |
|
504 } |
|
505 case EAknCmdHelp: |
|
506 if( iAddrFlags & EPostcardAddressHelpSupported ) |
|
507 { |
|
508 retVal = EFalse; |
|
509 } |
|
510 break; |
|
511 |
|
512 case EAknCmdExit: |
|
513 retVal = EFalse; |
|
514 break; |
|
515 |
|
516 default: |
|
517 break; |
|
518 } |
|
519 |
|
520 return retVal; |
|
521 } |
|
522 |
|
523 // --------------------------------------------------------- |
|
524 // DoSelectionKeyL |
|
525 // --------------------------------------------------------- |
|
526 void CPostcardAddressForm::DoSelectionKeyL( ) |
|
527 { |
|
528 TPostcardMsgType msgType = iDocument.MessageType( ); |
|
529 |
|
530 if( msgType != EPostcardSent ) |
|
531 { |
|
532 DoAddRecipientL( ); |
|
533 } |
|
534 } |
|
535 |
|
536 // --------------------------------------------------------- |
|
537 // OkToExitL(TInt aButtonId) |
|
538 // called by framework when the OK button is pressed |
|
539 // --------------------------------------------------------- |
|
540 TBool CPostcardAddressForm::OkToExitL( TInt aButtonId ) |
|
541 { |
|
542 TBool okToExit = CAknForm::OkToExitL( aButtonId ); |
|
543 if( aButtonId == EAknSoftkeyDone || aButtonId == EPostcardCmdSend ) |
|
544 { |
|
545 UpdateRecipientToEntryL(); |
|
546 return ETrue; |
|
547 } |
|
548 if( aButtonId == EAknCmdExit ) |
|
549 { |
|
550 return ETrue; |
|
551 } |
|
552 if( aButtonId == EAknSoftkeyEdit || aButtonId == EPostcardCmdAdd ) |
|
553 { |
|
554 DoAddRecipientL(); |
|
555 CheckTextExceedingL( ); |
|
556 SetMiddleSoftkeyL(); |
|
557 return EFalse; |
|
558 } |
|
559 if( !okToExit ) |
|
560 { |
|
561 return okToExit; |
|
562 } |
|
563 if( aButtonId == EAknSoftkeyBack || |
|
564 aButtonId == EAknSoftkeyExit || |
|
565 aButtonId == EAknSoftkeyDone || |
|
566 aButtonId == EAknCmdExit || |
|
567 aButtonId == EEikCmdExit ) |
|
568 { |
|
569 return okToExit; |
|
570 } |
|
571 return EFalse; |
|
572 } |
|
573 |
|
574 // --------------------------------------------------------- |
|
575 // ActivateL() |
|
576 // --------------------------------------------------------- |
|
577 void CPostcardAddressForm::ActivateL( ) |
|
578 { |
|
579 SetFocus( ETrue ); |
|
580 TInt focused = IdOfFocusControl( ); |
|
581 CEikEdwin* edwin = static_cast< CEikEdwin* >(Control( focused ) ); |
|
582 edwin->AddEdwinObserverL( this ); |
|
583 CCoeControl::ActivateL( ); |
|
584 |
|
585 // After activating -> lets set the max. lengths and hide if needed |
|
586 |
|
587 TryChangeFocusToL( iFirstActive==KErrNotFound?EPostcardAddressName:iFirstActive ); |
|
588 |
|
589 if( iFirstActive != KErrNotFound ) |
|
590 { // Lets show a note according to iFirstActive |
|
591 TInt resourceId; |
|
592 switch( iFirstActive ) |
|
593 { |
|
594 case EPostcardAddressName: |
|
595 resourceId = R_POSTCARD_ADDRESS_NAME; |
|
596 break; |
|
597 case EPostcardAddressInfo: |
|
598 resourceId = R_POSTCARD_ADDRESS_INFO; |
|
599 break; |
|
600 case EPostcardAddressStreet: |
|
601 resourceId = R_POSTCARD_ADDRESS_STREET; |
|
602 break; |
|
603 case EPostcardAddressZip: |
|
604 resourceId = R_POSTCARD_ADDRESS_ZIP; |
|
605 break; |
|
606 case EPostcardAddressCity: |
|
607 resourceId = R_POSTCARD_ADDRESS_CITY; |
|
608 break; |
|
609 case EPostcardAddressState: |
|
610 resourceId = R_POSTCARD_ADDRESS_STATE; |
|
611 break; |
|
612 default: |
|
613 resourceId = R_POSTCARD_ADDRESS_COUNTRY; |
|
614 break; |
|
615 } |
|
616 |
|
617 CEikEdwin* edwin2 = static_cast< CEikEdwin* >(ControlOrNull( iFirstActive ) ); |
|
618 if( edwin2 && edwin2->TextLength( ) ) |
|
619 { // It's too long |
|
620 if( edwin2->TextLength( ) > edwin2->MaxLength( ) + 1 ) |
|
621 { // Exceeded by many |
|
622 TInt howMany = edwin2->TextLength( ) - edwin2->MaxLength( ); |
|
623 HBufC* warningString = |
|
624 StringLoader::LoadLC( R_POSTCARD_ADDRESS_EXCEEDED_MANY, howMany, iCoeEnv ); |
|
625 iAppUi.ShowConfirmationQueryL( *warningString, ETrue ); |
|
626 CleanupStack::PopAndDestroy( warningString ); |
|
627 } |
|
628 else |
|
629 { // Exceeded by one |
|
630 iAppUi.ShowConfirmationQueryL( R_POSTCARD_ADDRESS_EXCEEDED, ETrue ); |
|
631 } |
|
632 iAddrFlags |= EPostcardAddressTextExceeded; |
|
633 } |
|
634 else |
|
635 { // It's empty |
|
636 HBufC* item = StringLoader::LoadLC( resourceId, iCoeEnv ); |
|
637 CDesCArray* stringArray = new ( ELeave ) CDesCArrayFlat( 2 ); |
|
638 CleanupStack::PushL( stringArray ); |
|
639 |
|
640 stringArray->AppendL( *item ); |
|
641 stringArray->AppendL( *item ); |
|
642 |
|
643 HBufC* note = StringLoader::LoadLC( R_POSTCARD_SEND_FIELD_EMPTY, *stringArray, iCoeEnv ); |
|
644 |
|
645 iAppUi.ShowInformationNoteL( note->Des( ), EFalse ); |
|
646 CleanupStack::PopAndDestroy( 3, item ); // item, stringarray, note |
|
647 } |
|
648 } |
|
649 |
|
650 if( iKeyEvent.iCode != 0 ) |
|
651 { |
|
652 TEventCode type = EEventKey; |
|
653 iCoeEnv->SyncNotifyFocusObserversOfChangeInFocus(); |
|
654 iCoeEnv->SimulateKeyEventL( iKeyEvent, type ); |
|
655 } |
|
656 } |
|
657 |
|
658 // --------------------------------------------------------- |
|
659 // HandleControlStateChangeL |
|
660 // --------------------------------------------------------- |
|
661 void CPostcardAddressForm::HandleControlStateChangeL( TInt /*aControlId*/ ) |
|
662 { |
|
663 |
|
664 } |
|
665 |
|
666 // --------------------------------------------------------- |
|
667 // HandleEdwinEventL |
|
668 // --------------------------------------------------------- |
|
669 void CPostcardAddressForm::HandleEdwinEventL(CEikEdwin* /*aEdwin*/, TEdwinEvent /*aEventType*/ ) |
|
670 { |
|
671 // The functionality has been removed to HandleControlEventL |
|
672 } |
|
673 |
|
674 // --------------------------------------------------------- |
|
675 // LineChangedL |
|
676 // --------------------------------------------------------- |
|
677 void CPostcardAddressForm::LineChangedL(TInt /*aControlId*/) |
|
678 { |
|
679 iAddrFlags &= ~EPostcardAddressTextExceeded; |
|
680 } |
|
681 |
|
682 // --------------------------------------------------------- |
|
683 // SendL |
|
684 // --------------------------------------------------------- |
|
685 void CPostcardAddressForm::SendL( ) |
|
686 { |
|
687 iRetValue = EPostcardDialogSend; |
|
688 TryExitL( EPostcardCmdSend ); |
|
689 } |
|
690 |
|
691 // --------------------------------------------------------- |
|
692 // ForwardMessageL |
|
693 // --------------------------------------------------------- |
|
694 void CPostcardAddressForm::ForwardMessageL( ) |
|
695 { |
|
696 iRetValue = EPostcardDialogForward; |
|
697 TryExitL( EAknSoftkeyDone ); |
|
698 } |
|
699 |
|
700 // --------------------------------------------------------- |
|
701 // MessageInfoL |
|
702 // --------------------------------------------------------- |
|
703 void CPostcardAddressForm::MessageInfoL( ) |
|
704 { |
|
705 TPostcardMsgType msgType = iDocument.MessageType( ); |
|
706 if( msgType != EPostcardSent ) |
|
707 { // We are dealing with unsent message -> save recipient details for now |
|
708 CEikEdwin* edwin = static_cast< CEikEdwin* >(ControlOrNull( EPostcardAddressName ) ); |
|
709 if( edwin ) |
|
710 { |
|
711 TMmsMsvEntry tEntry = static_cast<TMmsMsvEntry>( iDocument.Entry() ); |
|
712 tEntry.iDate.UniversalTime(); |
|
713 tEntry.iDetails.Set(edwin->Text( )->Read( 0, edwin->TextLength( ) ) ); |
|
714 tEntry.iBioType = KUidMsgSubTypeMmsPostcard.iUid; |
|
715 iDocument.CurrentEntry().ChangeL( tEntry ); |
|
716 } |
|
717 } |
|
718 iAppUi.DoShowMessageInfoL( ); |
|
719 } |
|
720 |
|
721 // --------------------------------------------------------- |
|
722 // LaunchHelpL |
|
723 // --------------------------------------------------------- |
|
724 void CPostcardAddressForm::LaunchHelpL( ) |
|
725 { |
|
726 if( iDocument.MessageType( ) == EPostcardSent ) |
|
727 { |
|
728 iAppUi.LaunchHelpL( KPOSTCARD_HLP_ADDRESS_VIEW() ); |
|
729 } |
|
730 else |
|
731 { |
|
732 iAppUi.LaunchHelpL( KMMS_POSTCARD_HLP_ADDRESS_EDIT() ); |
|
733 } |
|
734 } |
|
735 |
|
736 // --------------------------------------------------------- |
|
737 // CheckTextExceedingL |
|
738 // --------------------------------------------------------- |
|
739 void CPostcardAddressForm::CheckTextExceedingL( ) |
|
740 { |
|
741 if( iDocument.MessageType( ) == EPostcardSent ) |
|
742 { // we are just viewing the fields so no reason to show warnings |
|
743 return; |
|
744 } |
|
745 TInt focused = IdOfFocusControl( ); |
|
746 CEikEdwin* edwin = static_cast< CEikEdwin* >(Control( focused ) ); |
|
747 if ( !edwin ) |
|
748 { // just in case |
|
749 return; |
|
750 } |
|
751 TInt maxLength = edwin->MaxLength( ); |
|
752 |
|
753 if( edwin->TextLength( ) >= maxLength ) |
|
754 { |
|
755 TInt howMany = edwin->TextLength( ) - maxLength; |
|
756 switch( howMany ) |
|
757 { |
|
758 case 0: |
|
759 { |
|
760 // No note shown anymore. |
|
761 break; |
|
762 } |
|
763 case 1: |
|
764 { |
|
765 if( !( iAddrFlags & EPostcardAddressTextExceeded ) ) |
|
766 { |
|
767 iAppUi.ShowConfirmationQueryL( R_POSTCARD_ADDRESS_EXCEEDED, ETrue ); |
|
768 } |
|
769 break; |
|
770 } |
|
771 default: |
|
772 { |
|
773 if( !( iAddrFlags & EPostcardAddressTextExceeded ) ) |
|
774 { |
|
775 HBufC* warningString = |
|
776 StringLoader::LoadLC( R_POSTCARD_ADDRESS_EXCEEDED_MANY, howMany, iCoeEnv ); |
|
777 iAppUi.ShowConfirmationQueryL( *warningString, ETrue ); |
|
778 CleanupStack::PopAndDestroy( warningString ); |
|
779 } |
|
780 break; |
|
781 } |
|
782 } |
|
783 iAddrFlags |= EPostcardAddressTextExceeded; |
|
784 } |
|
785 else |
|
786 { |
|
787 iAddrFlags &= ~EPostcardAddressTextExceeded; |
|
788 } |
|
789 } |
|
790 |
|
791 // --------------------------------------------------------- |
|
792 // DoAddRecipientL |
|
793 // --------------------------------------------------------- |
|
794 void CPostcardAddressForm::DoAddRecipientL( ) |
|
795 { |
|
796 if ( !iContact ) |
|
797 { |
|
798 iContact = CPostcardContact::NewL( iCoeEnv->FsSession() ); |
|
799 } |
|
800 iContact->FetchContactL(); |
|
801 |
|
802 if ( iContact->IsValid() ) |
|
803 { |
|
804 // Reset the flag, so that user is notified if selected recipient |
|
805 // has too long address fields. |
|
806 iAddrFlags &= ~EPostcardAddressTextExceeded; |
|
807 |
|
808 CPostcardRecipientWrapper* recWrapper = |
|
809 CPostcardRecipientWrapper::NewL( iDocument, iAppUi, *iContact ); |
|
810 CleanupStack::PushL( recWrapper ); |
|
811 |
|
812 // Location asking is done in recipientWrapper |
|
813 CPostcardContact::TLocation location; |
|
814 TBool hasLocation = recWrapper->AskLocationL( location ); |
|
815 CleanupStack::PopAndDestroy( recWrapper ); |
|
816 |
|
817 if ( hasLocation ) |
|
818 { |
|
819 UpdateFieldsL( location ); |
|
820 RefreshDisplay(); // Refresh the dislay |
|
821 } |
|
822 } |
|
823 } |
|
824 |
|
825 // --------------------------------------------------------- |
|
826 // UpdateFieldsL |
|
827 // --------------------------------------------------------- |
|
828 void CPostcardAddressForm::UpdateFieldsL( CContactItem& aContact ) |
|
829 { |
|
830 CContactItemFieldSet& fieldSet = aContact.CardFields(); |
|
831 |
|
832 for( TInt i = 0; i < fieldSet.Count( ); i++ ) |
|
833 { |
|
834 CContactItemField& field = fieldSet[ i ]; |
|
835 if( field.StorageType( ) == KStorageTypeText ) |
|
836 { |
|
837 TInt destinationId = TPostcardUtils::IdFromContactItemName( field.Label( ) ); |
|
838 CEikEdwin* edwin = static_cast< CEikEdwin* >(ControlOrNull( destinationId ) ); |
|
839 if( edwin ) |
|
840 { |
|
841 HBufC* text = field.TextStorage()->Text().AllocLC( ); |
|
842 edwin->SetTextL( text ); |
|
843 edwin->SetCursorPosL( text->Length( ) - 1, EFalse ); |
|
844 CleanupStack::PopAndDestroy( text ); |
|
845 } |
|
846 } |
|
847 } |
|
848 } |
|
849 |
|
850 // --------------------------------------------------------- |
|
851 // UpdateFieldsL |
|
852 // --------------------------------------------------------- |
|
853 void CPostcardAddressForm::UpdateFieldsL( |
|
854 CPostcardContact::TLocation aLocation ) |
|
855 { |
|
856 // Update address fields |
|
857 for( TInt i = EPostcardAddressInfo; i <= EPostcardAddressCountry; i++ ) |
|
858 { |
|
859 CEikEdwin* edwin = static_cast<CEikEdwin*>( ControlOrNull( i ) ); |
|
860 if ( edwin ) |
|
861 { |
|
862 HBufC* text = iContact->GetAddressFieldLC( aLocation, |
|
863 CPostcardContact::ControlIdToAddrField( i ) ); |
|
864 edwin->SetTextL(text->Length() ? text:NULL); |
|
865 CleanupStack::PopAndDestroy( text ); // text |
|
866 } |
|
867 } |
|
868 |
|
869 // Update the name |
|
870 CEikEdwin* edwin = |
|
871 static_cast<CEikEdwin*>( ControlOrNull( EPostcardAddressName ) ); |
|
872 if ( edwin ) |
|
873 { |
|
874 HBufC* contactName = iContact->GetNameLC(); |
|
875 edwin->SetTextL( contactName->Length() ? contactName:NULL ); |
|
876 CleanupStack::PopAndDestroy( contactName ); // contactName |
|
877 } |
|
878 } |
|
879 |
|
880 // --------------------------------------------------------- |
|
881 // IsEmpty |
|
882 // --------------------------------------------------------- |
|
883 TBool CPostcardAddressForm::IsEmpty( ) |
|
884 { |
|
885 for(TInt loop = EPostcardAddressName; loop<=EPostcardAddressCountry; loop++ ) |
|
886 { |
|
887 CEikEdwin* edwin = static_cast< CEikEdwin* >(ControlOrNull( loop ) ); |
|
888 if( edwin && edwin->TextLength( ) > 0 ) |
|
889 { |
|
890 return EFalse; |
|
891 } |
|
892 } |
|
893 return ETrue; |
|
894 } |
|
895 |
|
896 // --------------------------------------------------------- |
|
897 // HandleControlEventL |
|
898 // --------------------------------------------------------- |
|
899 void CPostcardAddressForm::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent aEventType) |
|
900 { |
|
901 if( aEventType == EEventStateChanged ) |
|
902 { |
|
903 |
|
904 // Update middle softkey |
|
905 SetMiddleSoftkeyL(); |
|
906 } |
|
907 } |
|
908 |
|
909 // --------------------------------------------------------- |
|
910 // CleanNavipane |
|
911 // --------------------------------------------------------- |
|
912 void CPostcardAddressForm::CleanNavipane() |
|
913 { |
|
914 // Clean navigation pane, otherwise it can contain e.g. |
|
915 // character counter from greeting text editor, when user |
|
916 // tries to send a postcard without recipient's address. |
|
917 MAknEditingStateIndicator* editIndi = |
|
918 static_cast< CAknEnv* >( iEikonEnv->Extension( ) )->EditingStateIndicator(); |
|
919 if( editIndi ) |
|
920 { |
|
921 CAknIndicatorContainer* indiContainer = editIndi->IndicatorContainer( ); |
|
922 if ( indiContainer ) |
|
923 { |
|
924 indiContainer->SetIndicatorState( |
|
925 TUid::Uid( EAknNaviPaneEditorIndicatorMessageLength ), |
|
926 EAknIndicatorStateOff ); |
|
927 } |
|
928 } |
|
929 } |
|
930 |
|
931 |
|
932 // --------------------------------------------------------- |
|
933 // RefreshDisplay |
|
934 // --------------------------------------------------------- |
|
935 void CPostcardAddressForm::RefreshDisplay( ) |
|
936 { |
|
937 for(TInt loop = EPostcardAddressName; loop<=EPostcardAddressCountry; loop++ ) |
|
938 { |
|
939 CEikEdwin* edwin = static_cast< CEikEdwin* >(ControlOrNull( loop ) ); |
|
940 if( edwin ) |
|
941 { |
|
942 if( edwin->IsVisible( ) ) |
|
943 { |
|
944 edwin->DrawNow(); |
|
945 } |
|
946 } |
|
947 } |
|
948 } |
|
949 |
|
950 // --------------------------------------------------------- |
|
951 // SetMiddleSoftkeyL |
|
952 // --------------------------------------------------------- |
|
953 void CPostcardAddressForm::SetMiddleSoftkeyL() |
|
954 { |
|
955 TInt resourceId = R_POSTCARD_MSK_BUTTON_EMPTY; |
|
956 |
|
957 // Applying changes of the cr 403-1527 always from 5.0 onwards |
|
958 if ( iDocument.MessageType( ) != EPostcardSent ) |
|
959 { |
|
960 if( IsEmpty() ) |
|
961 { |
|
962 resourceId = R_POSTCARD_MSK_BUTTON_ADD; |
|
963 } |
|
964 else if( !IsEmpty() && IdOfFocusControl() == EPostcardAddressName ) |
|
965 { |
|
966 resourceId = R_POSTCARD_MSK_BUTTON_REPLACE; |
|
967 } |
|
968 } |
|
969 |
|
970 if ( resourceId != iMskResource) |
|
971 { |
|
972 const TInt KMskPosition = 3; |
|
973 CEikButtonGroupContainer& cba = ButtonGroupContainer(); |
|
974 cba.SetCommandL( KMskPosition, resourceId ); |
|
975 cba.DrawDeferred(); |
|
976 iMskResource = resourceId; |
|
977 } |
|
978 } |
|
979 |
|
980 // End of File |