|
1 /* |
|
2 * Copyright (c) 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: Key pattern matching component. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __LOCKAPPKEYPATTERN__ |
|
20 #define __LOCKAPPKEYPATTERN__ |
|
21 |
|
22 // INCLUDES |
|
23 #include <w32std.h> |
|
24 #include <e32base.h> |
|
25 |
|
26 enum TPatternState |
|
27 { |
|
28 EPatternNotInitialized = 1, |
|
29 EPatternNotEnabled, |
|
30 EPatternNoMatch, |
|
31 EPatternPrimaryMatch, |
|
32 EPatternSecondaryMatch, |
|
33 }; |
|
34 |
|
35 /** |
|
36 * CLockAppKeyPattern class implements a 2-key pattern matcher. |
|
37 * Can be used for both iCodes and iScancodes, as it matches integer numbers. |
|
38 * The caller's responsability is to make sense what is beeing matched. |
|
39 * Multiple patterns can be defined. |
|
40 * |
|
41 * @lib lockapp |
|
42 * @since 5.0 |
|
43 * @author Tamas Koteles |
|
44 */ |
|
45 class CLockAppKeyPattern : public CBase |
|
46 { |
|
47 public: |
|
48 |
|
49 /** |
|
50 * Two phased constructor. |
|
51 */ |
|
52 static CLockAppKeyPattern* NewL( ); |
|
53 |
|
54 /** |
|
55 * Destructor. |
|
56 */ |
|
57 ~CLockAppKeyPattern( ); |
|
58 |
|
59 /** |
|
60 * If no patterns have been defined it cannot be used. |
|
61 * @return ETrue if has succesfully loaded policy |
|
62 */ |
|
63 TBool HasPatterns( ); |
|
64 |
|
65 /** |
|
66 * Gets the enabled state. |
|
67 * |
|
68 * @return true if the patterns are enabled, false othewise |
|
69 */ |
|
70 TBool IsEnabled( ); |
|
71 |
|
72 /** |
|
73 * Sets the enabled state. |
|
74 */ |
|
75 void SetEnabled( TBool aEnabled ); |
|
76 |
|
77 /** |
|
78 * Gets the primary key timeout. |
|
79 * |
|
80 * @return the timeout in miliseconds |
|
81 */ |
|
82 TUint GetKeyTimeOut( ); |
|
83 |
|
84 /** |
|
85 * Sets the primary key timeout. |
|
86 * |
|
87 */ |
|
88 void SetKeyTimeOut( TUint aTimeOut ); |
|
89 |
|
90 /** |
|
91 * Adds a key combination. |
|
92 * |
|
93 * @param aPrimaryKey code for primary key |
|
94 * @param aSecondaryKey code for secondary key |
|
95 * @return standard Symbian error code |
|
96 */ |
|
97 TInt AddPattern( TUint32 aPrimaryKey, TUint32 aSecondaryKey ); |
|
98 |
|
99 /** |
|
100 * Gets a key combination. |
|
101 * |
|
102 * @param aIndex index of the key combination |
|
103 * @param aPrimaryKey primary key code if found |
|
104 * @param aSecondaryKey secondary key code if found |
|
105 * @return standard Symbian error code |
|
106 */ |
|
107 TInt GetPattern( TInt aIndex, TUint32& aPrimaryKey, TUint32& aSecondaryKey ); |
|
108 |
|
109 /** |
|
110 * Clears all the defined key combinations. |
|
111 * |
|
112 * @return standard Symbian error code |
|
113 */ |
|
114 TInt ClearPatterns( ); |
|
115 |
|
116 /** |
|
117 * Handles Key events. Result of the event is returned in the pattern state. |
|
118 * |
|
119 * @param aKey the actual key event (code or scancode) |
|
120 * @return TPatternState caused by the event. |
|
121 */ |
|
122 TPatternState HandleKeyEvent( TUint32 aKey ); |
|
123 |
|
124 protected: |
|
125 |
|
126 /** |
|
127 * C++ default constructor (private so cannot be derived). |
|
128 */ |
|
129 CLockAppKeyPattern( ); |
|
130 |
|
131 /** |
|
132 * Second constructor initializes the policy |
|
133 */ |
|
134 void ConstructL( ); |
|
135 |
|
136 private: |
|
137 |
|
138 /** |
|
139 * A primary key has been received, set primary-match state. |
|
140 */ |
|
141 void HandlePrimaryKeyEvent( TUint32 aKey ); |
|
142 |
|
143 /** |
|
144 * A secondary key has been received, set secondary-match state. |
|
145 */ |
|
146 void HandleSecondaryKeyEvent( ); |
|
147 |
|
148 /** |
|
149 * Any other key has been received, set no-match state. |
|
150 */ |
|
151 void HandleOtherKeyEvent( ); |
|
152 |
|
153 /** |
|
154 * A call back to the keylock timer |
|
155 * param TAny aSelf a pointer to the parent class |
|
156 */ |
|
157 static TInt HandleKeyTimerTimeout( TAny* aSelf ); |
|
158 |
|
159 private: |
|
160 |
|
161 // defined configurations |
|
162 RArray<TUint> iPrimaryKeys; |
|
163 RArray<TUint> iSecondaryKeys; |
|
164 RArray<TUint> iWaitingKeys; |
|
165 |
|
166 // defined timeout |
|
167 TUint iKeyTimeOut; |
|
168 |
|
169 // first key pressed |
|
170 TPatternState iState; |
|
171 |
|
172 // if the keypatterns are enabled |
|
173 TBool iEnabled; |
|
174 |
|
175 // if the keylock policy exists |
|
176 TBool iHasPatterns; |
|
177 |
|
178 // timer used between primary and secondary keys |
|
179 CPeriodic* iKeyTimer; |
|
180 |
|
181 }; |
|
182 |
|
183 #endif // __LOCKAPPKEYPATTERN__ |