2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Support for passwords in Settings Pages
21 #ifndef __AKNPASSWORDSETTINGPAGE__
22 #define __AKNPASSWORDSETTINGPAGE__
27 // for the alphanumeric secret editor:
29 #include <aknsettingpage.h>
31 const TInt KDefaultAlphaPasswordLength = 12;
32 const TInt KDefaultNumericPasswordLength = 4;
35 * Structure to hold the required resources for a password confirmation sequence
36 * This holds 3 resource IDs. One for a query, and a note each for
38 * This structure contains the information read in from a AVKON_PASSWORD_CONFIRMATION
41 class SAknConfirmationResource
46 * Resource for the password query, if non-zero
48 TInt iEntryQueryResourceId;
50 * Resource for the success note, if non-zero
52 TInt iSuccessNoteResourceId;
54 * Resource for the failure note, if non-zero
56 TInt iFailureNoteResourceId;
61 * Base class for Password editors to ensure that their general functionality is
64 * All contained-editor-specific stuff should be in the derived classes.
66 * THIS CLASS IS NOT INSTANTIATABLE
69 class CAknPasswordSettingPage : public CAknSettingPage
74 * Modes to be used for the matching of password texts
77 enum TAknPasswordMatchingMode
84 * Simple constructor depending only on a single resource Id and the new and old password.
85 * Editor resource is given via the link in the setting page resource.
87 * @param aSettingPageResourceId Setting Page to use (if present)
89 * @param aOldPassword password to be checked against
91 IMPORT_C CAknPasswordSettingPage(
94 const TDesC& aOldPassword);
97 * Constructor that allows separate setting page and editor resources
99 * This constructor allows the use of setting page using only the editor resource. Other combinations are also possible
101 * In all cases the number (if supplied i.e. <> 0 ) is used.
103 * Editor Resource Setting Page Resource
104 * present present Both are used (but text & number overridden)
105 * = 0 present Editor resource is used via SP resource (Effectively like the other constructor)
106 * present = 0 Default Avkon SP resource if used + this editor resource
107 * = 0 = 0 uses default resource for both SP and editor. This is OK if:
108 * i) control type is present,
109 * ii) a default resource exists ( OK for text, integer, date, time, duration )
111 * Note: The first argument is a TDesC* (rather than TDesC&) because the other constructor
112 * cannot initialize such a member without allocation or having an internal dummy buffer.
113 * This descriptor must be owned by the client since not copy is taken until ExecuteLD()
115 * Rules for text and numbers: The rules are the same for both: (non-zero length) text or number other
116 * than EAknSettingPageNoOrdinalDisplayed if given in this constructor will not override resource
117 * (unless that is zero length or EAknSettingPageNoOrdinalDisplayed). Note, however, that text or number given via the
118 * specific API for setting them, WILL override resource.
119 * It is assumed that number from resource is very rare. Special text is somewhat more likely.
121 * @param aSettingTitleText Text at top of setting pane; EXTERNALLY OWNED
122 * @param aSettingNumber Number at top left (if present)
123 * @param aControlType Determines the type constructed and how its resource is read
124 * @param aEditorResourceId Editor resource to use in the setting page (if present)
125 * @param aSettingPageResourceId Setting Page to use (if present)
126 * @param aNewPassword Descriptor for the new password
127 * @param aOldPassword Descriptor for the old password
130 IMPORT_C CAknPasswordSettingPage( const TDesC* aSettingTitleText,
133 TInt aEditorResourceId,
134 TInt aSettingPageResourceId,
136 const TDesC& aOldPassword );
140 * Set the resource Id set for the old password confirmation sequence.
141 * Resource Id should be for a AVKON_PASSWORD_CONFIRMATION structure
143 * @param resource for old password sequence
145 IMPORT_C void SetOldPasswordConfirmationResourceId( TInt aOldPasswordConfirmationResourceId );
148 * Set the resource Id set for the new password confirmation sequence
149 * Resource Id should be for a AVKON_PASSWORD_CONFIRMATION structure
151 * @param resource for new password sequence
153 IMPORT_C void SetNewPasswordConfirmationResourceId( TInt aNewPasswordConfirmationResourceId );
156 * Sets the matching mode to be used in the password validation
157 * @param one of ECaseSensitive or ECaseInsensitive
159 IMPORT_C void SetMatchingMode( TAknPasswordMatchingMode aMode );
162 * Returns the matching mode to be used in the password validation
163 * @return one of ECaseSensitive or ECaseInsensitive
165 IMPORT_C TAknPasswordMatchingMode MatchingMode();
169 * Sets the maximum length of the password. The user will not be able to enter
170 * more than this number of characters/keys
172 * @param set the max length
174 IMPORT_C void SetMaxPasswordLength( TInt aLength );
178 * Access the maximum password length
180 * @return the maximum length
182 IMPORT_C TInt MaxPasswordLength() const;
187 IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
191 * Implementation of CAknSettingPage framework method
192 * Called when the client's value is updated. Frequency of calling depends
193 * upon the flag passed to ExecuteLD()
196 IMPORT_C virtual void UpdateSettingL();
200 * Implementation of CAknSettingPage framework method
201 * Perform necessary operations when the user accepts.
202 * Default implementation has password checking
204 IMPORT_C virtual void AcceptSettingL();
208 * Acts upon changes in the hosted control's state.
210 * @param aControl The control changing its state (not used)
211 * @param aEventType The type of control event
213 IMPORT_C virtual void HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType );
217 * Implementation of CAknSettingPage framework method
219 * Method called after full construction and activation of the setting page
221 IMPORT_C virtual void PostDisplayInitL();
224 * Implementation of CAknSettingPage framework method
225 * Called after display of the setting page, but before the start of the
226 * setting page "waiting".
228 * If overidden, would normally hold a query.
230 * @return ETrue if OK to carry on; EFalse if setting it to be abandoned
233 IMPORT_C virtual TBool PostDisplayCheckL();
237 * Implementation of CAknSettingPage framework method
240 IMPORT_C virtual TBool OkToExitL(TBool aAccept);
243 * Implementation of CCoeControl framework method
244 * Called when the control has its size changed
246 IMPORT_C virtual void SizeChanged();
249 * Implementation of CCoeControl framework method
250 * Called when required to draw
252 IMPORT_C void Draw(const TRect& aRect) const;
255 * Only implemented in the derived classes
256 * Updates the text in the referenced password descriptor using a utility routine.
259 virtual void UpdateTextL() = 0;
262 * Framework for password handling
263 * Called when the old password is to be confirmed
264 * @param aPassword old password
265 * @param aResourceId AVKON_PASSWORD_CONFIRMATION id to use
267 IMPORT_C virtual TBool ExecuteOldPasswordConfirmationL(const TDesC& aPassword, TInt aPasswordConfirmationResourceId );
270 * Framework for password handling
271 * Called when the new password is to be confirmed
272 * @param aPassword new password
273 * @param aResourceId AVKON_PASSWORD_CONFIRMATION id to use
275 IMPORT_C virtual TBool ExecuteNewPasswordConfirmationL(const TDesC& aPassword, TInt aPasswordConfirmationResourceId );
278 * Framework for password handling
279 * Called to compare the two passwords
280 * @param reference (old) password
281 * @param candidate password; password just entered
283 IMPORT_C virtual TInt ComparePasswords( const TDesC& aRefPassword, const TDesC& aCandidatePassword, TAknPasswordMatchingMode ) const;
287 * Access to the old password confirmation resource
288 * @return id for AVKON_PASSWORD_CONFIRMATION structure
290 IMPORT_C TInt OldPasswordConfirmationResourceId() const;
294 * Access to the new password confirmation resource
295 * @return id for AVKON_PASSWORD_CONFIRMATION structure
297 IMPORT_C TInt NewPasswordConfirmationResourceId() const;
301 * Read in the confirmation resource structure
302 * @param aPasswordResourceId id to use
303 * @param aResourceGroup structure to fill
305 IMPORT_C void ReadConfirmationResourceL( TInt aPasswordResourceId, SAknConfirmationResource& aResourceGroup );
309 * Run the password confirmation
311 IMPORT_C TBool DoPasswordConfirmationL(const TDesC& aPassword, TInt aPasswordConfirmationResourceId, TAknPasswordMatchingMode aMatchMode, TInt& aTries );
315 * Access to new password candidate
318 IMPORT_C TDes& NewPassword() const;
322 * Access to old password
324 IMPORT_C const TDesC& OldPassword() const;
327 // CoeControl Framework and reserved methods
332 * Writes the internal state of the control and its components to aStream.
333 * Does nothing in release mode.
334 * Designed to be overidden and base called by subclasses.
336 * @param aWriteSteam A connected write stream
338 IMPORT_C virtual void WriteInternalStateL(RWriteStream& aWriteStream) const;
343 * Reserved method derived from CCoeControl
345 IMPORT_C virtual void Reserved_2();
351 IMPORT_C void* ExtensionInterface( TUid aInterface );
354 * New reserved methods for CAknSettingPage hierarchy
357 IMPORT_C virtual void CAknSettingPage_Reserved_1();
358 IMPORT_C virtual void CAknSettingPage_Reserved_2();
362 const TDesC& iOldPassword;
363 TInt iOldPasswordConfirmationResourceId;
364 TInt iNewPasswordConfirmationResourceId;
365 TAknPasswordMatchingMode iMatchingMode;
366 TInt iMaxPasswordLength;
368 TAknLayoutRect iSecretEditorLayoutRect;
369 TAknLayoutRect iHorizontalShadow;
370 TAknLayoutRect iVerticalShadow;
371 TAknLayoutRect iOutlineFrame;
380 * This class is used for alphanumeric passwords
384 class CAknAlphaPasswordSettingPage : public CAknPasswordSettingPage
388 * Simple constructor depending only on a single resource Id and the new and old password.
389 * Editor resource is given via the link in the setting page resource.
391 * @param aSettingPageResourceId Setting Page to use (if present)
392 * @param aNewPassword
393 * @param aOldPassword password to be checked against
395 IMPORT_C CAknAlphaPasswordSettingPage(
398 const TDesC& aOldPassword);
400 * Constructor that allows separate setting page and editor resources
402 * This constructor allows the use of setting page using only the editor resource. Other combinations are also possible
404 * In all cases the number (if supplied i.e. <> 0 ) is used.
406 * Editor Resource Setting Page Resource
407 * present present Both are used (but text & number overridden)
408 * = 0 present Editor resource is used via SP resource (Effectively like the other constructor)
409 * present = 0 Default Avkon SP resource if used + this editor resource
410 * = 0 = 0 uses default resource for both SP and editor. This is OK if:
411 * i) control type is present,
412 * ii) a default resource exists ( OK for text, integer, date, time, duration )
414 * Note: The first argument is a TDesC* (rather than TDesC&) because the other constructor
415 * cannot initialize such a member without allocation or having an internal dummy buffer.
416 * This descriptor must be owned by the client since not copy is taken until ExecuteLD()
418 * Rules for text and numbers: The rules are the same for both: (non-zero length) text or number other
419 * than EAknSettingPageNoOrdinalDisplayed if given in this constructor will not override resource
420 * (unless that is zero length or EAknSettingPageNoOrdinalDisplayed). Note, however, that text or number given via the
421 * specific API for setting them, WILL override resource.
422 * It is assumed that number from resource is very rare. Special text is somewhat more likely.
424 * @param aSettingTitleText Text at top of setting pane; EXTERNALLY OWNED
425 * @param aSettingNumber Number at top left (if present)
426 * @param aControlType Determines the type constructed and how its resource is read
427 * @param aEditorResourceId Editor resource to use in the setting page (if present)
428 * @param aSettingPageResourceId Setting Page to use (if present)
429 * @param aNewPassword Descriptor for the new password
430 * @param aOldPassword Descriptor for the old password
432 IMPORT_C CAknAlphaPasswordSettingPage( const TDesC* aSettingTitleText,
435 TInt aEditorResourceId,
436 TInt aSettingPageResourceId,
438 const TDesC& aOldPassword );
442 * 2nd stage construction. This uses stored values from the constructor to allocate the
443 * required aggregate objects, and then set the Date value.
446 IMPORT_C virtual void ConstructL();
449 * Type specific access to hosted editor
450 * @return the hosted (alpha secret) editor
452 IMPORT_C CEikSecretEditor* AlphaPasswordEditor();
456 * Handles pointer events
457 * @param aPointerEvent The pointer event.
459 IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
465 IMPORT_C virtual ~CAknAlphaPasswordSettingPage();
468 * From CAknPasswordSettingPage - Implemented in this class
469 * Copy text from the editor to the client's descriptor
471 IMPORT_C virtual void UpdateTextL();
474 * Framework for password handling
475 * Called to compare the two passwords
476 * @param reference (old) password
477 * @param candidate password; password just entered
479 IMPORT_C virtual TInt ComparePasswords( const TDesC& aRefPassword, const TDesC& aCandidatePassword, TAknPasswordMatchingMode ) const;
482 // CoeControl Framework and reserved methods
487 * Writes the internal state of the control and its components to aStream.
488 * Does nothing in release mode.
489 * Designed to be overidden and base called by subclasses.
491 * @param aWriteSteam A connected write stream
493 IMPORT_C virtual void WriteInternalStateL(RWriteStream& aWriteStream) const;
498 * Reserved method derived from CCoeControl
500 IMPORT_C virtual void Reserved_2();
506 IMPORT_C void* ExtensionInterface( TUid aInterface );
509 * New reserved methods for CAknSettingPage hierarchy
512 IMPORT_C virtual void CAknSettingPage_Reserved_1();
513 IMPORT_C virtual void CAknSettingPage_Reserved_2();
522 * This class is used for numeric passwords. The API uses text descriptors rather than
523 * integers for the PIN numbers as this is the usage
527 #include <Aknnumseced.h>
529 class CAknNumericPasswordSettingPage : public CAknPasswordSettingPage
533 * Simple constructor depending only on a single resource Id and the new and old password.
534 * Editor resource is given via the link in the setting page resource.
536 * @param aSettingPageResourceId Setting Page to use (if present)
537 * @param aNewPassword
538 * @param aOldPassword password to be checked against
540 IMPORT_C CAknNumericPasswordSettingPage(
543 const TDesC& aOldPassword);
545 * Constructor that allows separate setting page and editor resources
547 * This constructor allows the use of setting page using only the editor resource. Other combinations are also possible
549 * In all cases the number (if supplied i.e. <> 0 ) is used.
551 * Editor Resource Setting Page Resource
552 * present present Both are used (but text & number overridden)
553 * = 0 present Editor resource is used via SP resource (Effectively like the other constructor)
554 * present = 0 Default Avkon SP resource if used + this editor resource
555 * = 0 = 0 uses default resource for both SP and editor. This is OK if:
556 * i) control type is present,
557 * ii) a default resource exists ( OK for text, integer, date, time, duration )
559 * Note: The first argument is a TDesC* (rather than TDesC&) because the other constructor
560 * cannot initialize such a member without allocation or having an internal dummy buffer.
561 * This descriptor must be owned by the client since not copy is taken until ExecuteLD()
563 * Rules for text and numbers: The rules are the same for both: (non-zero length) text or number other
564 * than EAknSettingPageNoOrdinalDisplayed if given in this constructor will not override resource
565 * (unless that is zero length or EAknSettingPageNoOrdinalDisplayed). Note, however, that text or number given via the
566 * specific API for setting them, WILL override resource.
567 * It is assumed that number from resource is very rare. Special text is somewhat more likely.
569 * @param aSettingTitleText Text at top of setting pane; EXTERNALLY OWNED
570 * @param aSettingNumber Number at top left (if present)
571 * @param aControlType Determines the type constructed and how its resource is read
572 * @param aEditorResourceId Editor resource to use in the setting page (if present)
573 * @param aSettingPageResourceId Setting Page to use (if present)
574 * @param aNewPassword Descriptor for the new password
575 * @param aOldPassword Descriptor for the old password
577 IMPORT_C CAknNumericPasswordSettingPage( const TDesC* aSettingTitleText,
580 TInt aEditorResourceId,
581 TInt aSettingPageResourceId,
583 const TDesC& aOldPassword );
587 * 2nd stage construction. This uses stored values from the conststuctor to allocate the
588 * required aggregate objects, and then set the Date value.
591 IMPORT_C virtual void ConstructL();
594 * Type specific access to hosted editor
595 * @return the hosted (numeric secret) editor
597 IMPORT_C CAknNumericSecretEditor* NumericPasswordEditor();
601 * Handles pointer events
602 * @param aPointerEvent The pointer event.
604 IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
610 IMPORT_C virtual ~CAknNumericPasswordSettingPage();
613 * From CAknPasswordSettingPage - Implemented in this class
614 * Copy text from the editor to the client's descriptor
616 IMPORT_C virtual void UpdateTextL();
619 // CoeControl Framework and reserved methods
624 * Writes the internal state of the control and its components to aStream.
625 * Does nothing in release mode.
626 * Designed to be overidden and base called by subclasses.
628 * @param aWriteSteam A connected write stream
630 IMPORT_C virtual void WriteInternalStateL(RWriteStream& aWriteStream) const;
635 * Reserved method derived from CCoeControl
637 IMPORT_C virtual void Reserved_2();
643 IMPORT_C void* ExtensionInterface( TUid aInterface );
646 * New reserved methods for CAknSettingPage hierarchy
649 IMPORT_C virtual void CAknSettingPage_Reserved_1();
650 IMPORT_C virtual void CAknSettingPage_Reserved_2();