|
1 /* |
|
2 * Copyright (c) 2005-2009 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 the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "T_DataWsPriorityKeyEvent.h" |
|
19 #include "T_GraphicsUtil.h" |
|
20 |
|
21 /*@{*/ |
|
22 //Commands |
|
23 _LIT(KCmdnew, "new"); |
|
24 _LIT(KCmdDestructor, "~"); |
|
25 _LIT(KCmdHandle, "Handle"); |
|
26 _LIT(KCmdKey, "Key"); |
|
27 _LIT(KCmdSetHandle, "SetHandle"); |
|
28 |
|
29 // Fields |
|
30 _LIT(KFldExpected, "expected"); |
|
31 _LIT(KFldExpected_Code, "expected_code"); |
|
32 _LIT(KFldExpected_Modifier, "expected_modifier"); |
|
33 _LIT(KFldExpected_Repeats, "expected_repeats"); |
|
34 _LIT(KFldExpected_ScanCode, "expected_scancode"); |
|
35 _LIT(KFldHandle, "handle"); |
|
36 |
|
37 /// Logging |
|
38 _LIT(KLogError, "Error=%d"); |
|
39 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
40 _LIT(KLogMissingExpectedValue, "Missing expected value '%S'"); |
|
41 _LIT(KLogNotExpectedValueInt, "'%S' is not as expected=%d, actual=%d"); |
|
42 /*@}*/ |
|
43 |
|
44 ////////////////////////////////////////////////////////////////////// |
|
45 // Construction/Destruction |
|
46 ////////////////////////////////////////////////////////////////////// |
|
47 |
|
48 CT_DataWsPriorityKeyEvent* CT_DataWsPriorityKeyEvent::NewL() |
|
49 { |
|
50 CT_DataWsPriorityKeyEvent* ret=new (ELeave) CT_DataWsPriorityKeyEvent(); |
|
51 CleanupStack::PushL(ret); |
|
52 ret->ConstructL(); |
|
53 CleanupStack::Pop(ret); |
|
54 return ret; |
|
55 } |
|
56 |
|
57 CT_DataWsPriorityKeyEvent::CT_DataWsPriorityKeyEvent() |
|
58 : CDataWrapperBase() |
|
59 , iWsPriorityKeyEvent(NULL) |
|
60 { |
|
61 } |
|
62 |
|
63 void CT_DataWsPriorityKeyEvent::ConstructL() |
|
64 { |
|
65 } |
|
66 |
|
67 CT_DataWsPriorityKeyEvent::~CT_DataWsPriorityKeyEvent() |
|
68 { |
|
69 DestroyData(); |
|
70 } |
|
71 |
|
72 void CT_DataWsPriorityKeyEvent::SetObjectL(TAny* aAny) |
|
73 { |
|
74 DestroyData(); |
|
75 iWsPriorityKeyEvent = static_cast<TWsPriorityKeyEvent*> (aAny); |
|
76 } |
|
77 |
|
78 void CT_DataWsPriorityKeyEvent::DisownObjectL() |
|
79 { |
|
80 iWsPriorityKeyEvent = NULL; |
|
81 } |
|
82 |
|
83 void CT_DataWsPriorityKeyEvent::DestroyData() |
|
84 { |
|
85 delete iWsPriorityKeyEvent; |
|
86 iWsPriorityKeyEvent=NULL; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Process a command read from the ini file |
|
91 * |
|
92 * @param aCommand the command to process |
|
93 * @param aSection the entry in the ini file requiring the command to be processed |
|
94 * @param aAsyncErrorIndex index of command. used for async calls |
|
95 * |
|
96 * @return ETrue if the command is processed |
|
97 */ |
|
98 TBool CT_DataWsPriorityKeyEvent::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
99 { |
|
100 TBool ret = ETrue; |
|
101 if ( aCommand==KCmdnew ) |
|
102 { |
|
103 DoCmdnew(); |
|
104 } |
|
105 else if ( aCommand==KCmdDestructor ) |
|
106 { |
|
107 DestroyData(); |
|
108 } |
|
109 else if ( aCommand==KCmdHandle ) |
|
110 { |
|
111 DoCmdHandle(aSection); |
|
112 } |
|
113 else if ( aCommand==KCmdKey ) |
|
114 { |
|
115 DoCmdKey(aSection); |
|
116 } |
|
117 else if ( aCommand==KCmdSetHandle ) |
|
118 { |
|
119 DoCmdSetHandle(aSection); |
|
120 } |
|
121 else |
|
122 { |
|
123 ret=EFalse; |
|
124 } |
|
125 |
|
126 return ret; |
|
127 } |
|
128 |
|
129 |
|
130 |
|
131 void CT_DataWsPriorityKeyEvent::DoCmdnew() |
|
132 { |
|
133 DestroyData(); |
|
134 INFO_PRINTF1(_L("execute new TWsPriorityKeyEvent()")); |
|
135 TRAPD(err, iWsPriorityKeyEvent = new (ELeave) TWsPriorityKeyEvent()); |
|
136 if ( err!=KErrNone ) |
|
137 { |
|
138 ERR_PRINTF2(KLogError, err); |
|
139 SetError(err); |
|
140 } |
|
141 } |
|
142 |
|
143 |
|
144 void CT_DataWsPriorityKeyEvent::DoCmdSetHandle(const TDesC& aSection) |
|
145 { |
|
146 TInt handle; |
|
147 |
|
148 if ( !GetIntFromConfig(aSection, KFldHandle(), handle) ) |
|
149 { |
|
150 ERR_PRINTF2(KLogMissingParameter, &KFldHandle); |
|
151 SetBlockResult(EFail); |
|
152 } |
|
153 else |
|
154 { |
|
155 INFO_PRINTF1(_L("execute SetHandle(TUint)")); |
|
156 iWsPriorityKeyEvent->SetHandle((TUint)handle); |
|
157 } |
|
158 } |
|
159 |
|
160 |
|
161 void CT_DataWsPriorityKeyEvent::DoCmdHandle(const TDesC& aSection) |
|
162 { |
|
163 INFO_PRINTF1(_L("execute Handle()")); |
|
164 TUint actual=iWsPriorityKeyEvent->Handle(); |
|
165 SetHandle(actual); |
|
166 |
|
167 TInt expected; |
|
168 if ( GetIntFromConfig(aSection, KFldExpected, expected) ) |
|
169 { |
|
170 if ( actual!= (TUint)expected ) |
|
171 { |
|
172 ERR_PRINTF4(KLogNotExpectedValueInt, &KFldExpected, expected, actual); |
|
173 SetBlockResult(EFail); |
|
174 } |
|
175 } |
|
176 else |
|
177 { |
|
178 ERR_PRINTF2(KLogMissingExpectedValue, &KFldExpected); |
|
179 SetBlockResult(EFail); |
|
180 } |
|
181 } |
|
182 |
|
183 |
|
184 void CT_DataWsPriorityKeyEvent::DoCmdKey(const TDesC& aSection) |
|
185 { |
|
186 INFO_PRINTF1(_L("execute Key()")); |
|
187 TKeyEvent* eventKey=iWsPriorityKeyEvent->Key(); |
|
188 |
|
189 TKeyCode keyCode; |
|
190 if ( CT_GraphicsUtil::ReadKeyCode(*this, aSection, KFldExpected_Code, keyCode) ) |
|
191 { |
|
192 if ( (TUint)keyCode != eventKey->iCode ) |
|
193 { |
|
194 ERR_PRINTF4(KLogNotExpectedValueInt, &KFldExpected_Code, keyCode, eventKey->iCode); |
|
195 SetBlockResult(EFail); |
|
196 } |
|
197 } |
|
198 else |
|
199 { |
|
200 ERR_PRINTF2(KLogMissingExpectedValue, &KFldExpected_Code); |
|
201 SetBlockResult(EFail); |
|
202 } |
|
203 |
|
204 TStdScanCode scanCode; |
|
205 if ( CT_GraphicsUtil::ReadStdScanCode(*this, aSection, KFldExpected_ScanCode, scanCode) ) |
|
206 { |
|
207 if ( scanCode != eventKey->iScanCode ) |
|
208 { |
|
209 ERR_PRINTF4(KLogNotExpectedValueInt, &KFldExpected_ScanCode, scanCode, eventKey->iScanCode); |
|
210 SetBlockResult(EFail); |
|
211 } |
|
212 } |
|
213 |
|
214 TUint modifiers; |
|
215 if ( CT_GraphicsUtil::ReadEventModifier(*this, aSection, KFldExpected_Modifier, modifiers) ) |
|
216 { |
|
217 if ( modifiers != eventKey->iModifiers ) |
|
218 { |
|
219 ERR_PRINTF4(KLogNotExpectedValueInt, &KFldExpected_Modifier, modifiers, eventKey->iModifiers); |
|
220 SetBlockResult(EFail); |
|
221 } |
|
222 } |
|
223 |
|
224 TInt repeats; |
|
225 if ( GetIntFromConfig(aSection, KFldExpected_Repeats, repeats) ) |
|
226 { |
|
227 if ( repeats != eventKey->iRepeats ) |
|
228 { |
|
229 ERR_PRINTF4(KLogNotExpectedValueInt, &KFldExpected_Repeats, repeats, eventKey->iRepeats); |
|
230 SetBlockResult(EFail); |
|
231 } |
|
232 } |
|
233 } |
|
234 |