|
1 /* |
|
2 * Copyright (c) 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 "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: This module contains implementation of CMenuNotifier |
|
15 * and CMenuDialog class implementations. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <e32cons.h> |
|
22 #include <e32svr.h> |
|
23 #include <f32file.h> |
|
24 #include "ConsoleUI.h" |
|
25 #include "ConsoleMenus.h" |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 |
|
29 // EXTERNAL FUNCTION PROTOTYPES |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KDefaultTime = 2; |
|
33 |
|
34 // MACROS |
|
35 #ifndef __WINS__ |
|
36 #define GETPTR & |
|
37 #else |
|
38 #define GETPTR |
|
39 #endif |
|
40 |
|
41 // LOCAL CONSTANTS AND MACROS |
|
42 |
|
43 // MODULE DATA STRUCTURES |
|
44 |
|
45 // LOCAL FUNCTION PROTOTYPES |
|
46 |
|
47 // FORWARD DECLARATIONS |
|
48 |
|
49 |
|
50 // ==================== LOCAL FUNCTIONS ======================================= |
|
51 |
|
52 // None |
|
53 |
|
54 |
|
55 |
|
56 // ================= MEMBER FUNCTIONS ========================================= |
|
57 |
|
58 /* |
|
59 ------------------------------------------------------------------------------- |
|
60 |
|
61 Class: CMenuNotifier |
|
62 |
|
63 Method: NewL |
|
64 |
|
65 Description: Constructs new menu notifier |
|
66 |
|
67 Parameters: CConsoleMain* aConsole :in: Pointer to main console |
|
68 CMenu* aParent :in: Parent menu |
|
69 const TDesC& aName :in: Menu name |
|
70 |
|
71 Return Values: CMenu* New menu |
|
72 |
|
73 Errors/Exceptions: Leaves if memory allocation fails |
|
74 Leaves if ConstructL leaves. |
|
75 |
|
76 Status: Draft |
|
77 |
|
78 ------------------------------------------------------------------------------- |
|
79 */ |
|
80 CMenuNotifier* CMenuNotifier::NewL( const TDesC& aError, CConsoleMain* aMain ) |
|
81 { |
|
82 |
|
83 CMenuNotifier* self = new ( ELeave ) CMenuNotifier( aMain ); |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL( aError ); |
|
86 CleanupStack::Pop( self ); |
|
87 return self; |
|
88 |
|
89 } |
|
90 |
|
91 |
|
92 /* |
|
93 ------------------------------------------------------------------------------- |
|
94 |
|
95 Class: CMenuNotifier |
|
96 |
|
97 Method: ConstructL |
|
98 |
|
99 Description: Second level constructor. |
|
100 |
|
101 Parameters: CConsoleMain* aConsole :in: Pointer to main console |
|
102 CMenu* aParent :in: Parent menu |
|
103 const TDesC& aName :in: Menu name |
|
104 |
|
105 Return Values: None |
|
106 |
|
107 Errors/Exceptions: None |
|
108 |
|
109 Status: Draft |
|
110 |
|
111 ------------------------------------------------------------------------------- |
|
112 */ |
|
113 void CMenuNotifier::ConstructL( const TDesC& aError ) |
|
114 { |
|
115 |
|
116 TSize size = iMain->GetConsole()->ScreenSize(); |
|
117 size.iWidth = Min( size.iWidth - KMenuOverhead, |
|
118 aError.Length() ); |
|
119 size.iHeight = aError.Length()/size.iWidth + 2; |
|
120 |
|
121 iConsole = Console::NewL( _L("Error note"), size ); |
|
122 |
|
123 iConsole->Printf( _L("Error:") ); |
|
124 iConsole->Printf( aError ); |
|
125 iConsole->Printf( _L("\n") ); |
|
126 iConsole->Printf( _L("Press any key") ); |
|
127 |
|
128 iTimer.CreateLocal(); |
|
129 |
|
130 CActiveScheduler::Add ( &iCallBack1 ); |
|
131 CActiveScheduler::Add ( &iCallBack2 ); |
|
132 |
|
133 // Get timer |
|
134 iTimer.After( iCallBack1.Activate(), 10000000 ); |
|
135 |
|
136 // Poll keypresses |
|
137 iConsole->Read ( iCallBack2.Activate() ); |
|
138 |
|
139 } |
|
140 |
|
141 /* |
|
142 ------------------------------------------------------------------------------- |
|
143 |
|
144 Class: CMenuNotifier |
|
145 |
|
146 Method: CMenuNotifier |
|
147 |
|
148 Description: Constructor |
|
149 |
|
150 Parameters: None |
|
151 |
|
152 Return Values: None |
|
153 |
|
154 Errors/Exceptions: None |
|
155 |
|
156 Status: Draft |
|
157 |
|
158 ------------------------------------------------------------------------------- |
|
159 */ |
|
160 #pragma warning( disable : 4355 ) // Incomplete this usage |
|
161 CMenuNotifier::CMenuNotifier( CConsoleMain* aMain ): |
|
162 iCallBack1 ( this, GETPTR CMenuNotifier::Run1 ), |
|
163 iCallBack2 ( this, GETPTR CMenuNotifier::Run1 ), |
|
164 iMain( aMain ) |
|
165 { |
|
166 } |
|
167 #pragma warning( default : 4355 ) |
|
168 |
|
169 /* |
|
170 ------------------------------------------------------------------------------- |
|
171 e |
|
172 Class: CMenuNotifier |
|
173 |
|
174 Method: ~CMenuNotifier |
|
175 |
|
176 Description: Destructor |
|
177 |
|
178 Parameters: None |
|
179 |
|
180 Return Values: None |
|
181 |
|
182 Errors/Exceptions: None |
|
183 |
|
184 Status: Draft |
|
185 |
|
186 ------------------------------------------------------------------------------- |
|
187 */ |
|
188 CMenuNotifier::~CMenuNotifier() |
|
189 { |
|
190 iTimer.Close(); |
|
191 delete iConsole; |
|
192 |
|
193 } |
|
194 |
|
195 |
|
196 |
|
197 /* |
|
198 ------------------------------------------------------------------------------- |
|
199 |
|
200 Class: CMenuNotifier |
|
201 |
|
202 Method: Run1 |
|
203 |
|
204 Description: Callback function. Closes dialog |
|
205 |
|
206 Parameters: None |
|
207 |
|
208 Return Values: None |
|
209 |
|
210 Errors/Exceptions: None |
|
211 |
|
212 Status: Draft |
|
213 |
|
214 ------------------------------------------------------------------------------- |
|
215 */ |
|
216 void CMenuNotifier::Run1() |
|
217 { |
|
218 |
|
219 if ( iCallBack1.isCompleted() && iCallBack2.isCompleted() ) |
|
220 { |
|
221 // Both callback have been done, delete this object |
|
222 delete this; |
|
223 return; |
|
224 } |
|
225 else |
|
226 { |
|
227 // One callback finished, stop listening anything else |
|
228 iConsole->ReadCancel(); |
|
229 iTimer.Cancel(); |
|
230 } |
|
231 } |
|
232 |
|
233 |
|
234 // ================= MEMBER FUNCTIONS ========================================= |
|
235 |
|
236 /* |
|
237 ------------------------------------------------------------------------------- |
|
238 |
|
239 Class: CMenuDialog |
|
240 |
|
241 Method: NewL |
|
242 |
|
243 Description: Constructs new menu dialog |
|
244 |
|
245 Parameters: const TDesC& aMessage: in: Message to dialog |
|
246 |
|
247 Return Values: CMenu* New menu |
|
248 |
|
249 Errors/Exceptions: Leaves if memory allocation fails |
|
250 Leaves if ConstructL leaves. |
|
251 |
|
252 Status: Draft |
|
253 |
|
254 ------------------------------------------------------------------------------- |
|
255 */ |
|
256 CMenuDialog* CMenuDialog::NewL( CConsoleMain* aMain, |
|
257 const TDesC& aLine1, |
|
258 const TDesC& aLine2, |
|
259 TInt aTimeInSecs ) |
|
260 { |
|
261 |
|
262 CMenuDialog* self = new ( ELeave ) CMenuDialog( aMain ); |
|
263 CleanupStack::PushL( self ); |
|
264 self->ConstructL( aLine1, aLine2, aTimeInSecs ); |
|
265 CleanupStack::Pop( self ); |
|
266 return self; |
|
267 |
|
268 } |
|
269 |
|
270 |
|
271 /* |
|
272 ------------------------------------------------------------------------------- |
|
273 |
|
274 Class: CMenuDialog |
|
275 |
|
276 Method: ConstructL |
|
277 |
|
278 Description: Second level constructor. |
|
279 |
|
280 Parameters: const TDesC& aMessage: in: Message to dialog |
|
281 |
|
282 Return Values: None |
|
283 |
|
284 Errors/Exceptions: None |
|
285 |
|
286 Status: Draft |
|
287 |
|
288 ------------------------------------------------------------------------------- |
|
289 */ |
|
290 void CMenuDialog::ConstructL( const TDesC& aLine1, |
|
291 const TDesC& aLine2, |
|
292 TInt aTimeInSecs ) |
|
293 { |
|
294 |
|
295 TSize size = iMain->GetConsole()->ScreenSize(); |
|
296 size.iWidth = Min( size.iWidth - KMenuOverhead, |
|
297 Max( aLine1.Length(), aLine2.Length() ) ); |
|
298 size.iHeight = aLine1.Length()/size.iWidth + aLine2.Length()/size.iWidth + 2; |
|
299 |
|
300 iConsole = Console::NewL( _L("Info"), size ); |
|
301 |
|
302 if( aLine1.Length() > 0 ) |
|
303 { |
|
304 iConsole->Printf( aLine1 ); |
|
305 } |
|
306 if( aLine2.Length() > 0 ) |
|
307 { |
|
308 iConsole->Printf( _L("\n") ); |
|
309 iConsole->Printf( aLine2 ); |
|
310 } |
|
311 |
|
312 if( aTimeInSecs == 0 ) |
|
313 { |
|
314 aTimeInSecs = KDefaultTime; |
|
315 } |
|
316 iTimer.CreateLocal(); |
|
317 |
|
318 CActiveScheduler::Add ( &iCallBack1 ); |
|
319 // Get timer |
|
320 iTimer.After( iCallBack1.Activate(), aTimeInSecs*1000*1000 ); |
|
321 |
|
322 } |
|
323 |
|
324 /* |
|
325 ------------------------------------------------------------------------------- |
|
326 |
|
327 Class: CMenuDialog |
|
328 |
|
329 Method: CMenuDialog |
|
330 |
|
331 Description: Constructor |
|
332 |
|
333 Parameters: None |
|
334 |
|
335 Return Values: None |
|
336 |
|
337 Errors/Exceptions: None |
|
338 |
|
339 Status: Draft |
|
340 |
|
341 ------------------------------------------------------------------------------- |
|
342 */ |
|
343 #pragma warning( disable : 4355 ) // Incomplete this usage |
|
344 CMenuDialog::CMenuDialog( CConsoleMain* aMain ): |
|
345 iMain( aMain ), |
|
346 iCallBack1 ( this, GETPTR CMenuDialog::Run1 ), |
|
347 iCallBack2 ( this, GETPTR CMenuDialog::Run1 ) |
|
348 { |
|
349 } |
|
350 #pragma warning( default : 4355 ) |
|
351 |
|
352 /* |
|
353 ------------------------------------------------------------------------------- |
|
354 e |
|
355 Class: CMenuDialog |
|
356 |
|
357 Method: ~CMenuDialog |
|
358 |
|
359 Description: Destructor |
|
360 |
|
361 Parameters: None |
|
362 |
|
363 Return Values: None |
|
364 |
|
365 Errors/Exceptions: None |
|
366 |
|
367 Status: Draft |
|
368 |
|
369 ------------------------------------------------------------------------------- |
|
370 */ |
|
371 CMenuDialog::~CMenuDialog() |
|
372 { |
|
373 |
|
374 //if( iCallBack1.IsActive() ) |
|
375 // { |
|
376 iTimer.Cancel(); |
|
377 iTimer.Close(); |
|
378 iCallBack1.Cancel(); |
|
379 // } |
|
380 |
|
381 if( iCallBack2.IsActive() ) |
|
382 { |
|
383 User::RequestComplete( iStatus, KErrCancel ); |
|
384 if( iConsole != NULL ) |
|
385 { |
|
386 iConsole->ReadCancel(); |
|
387 } |
|
388 iCallBack2.Cancel(); |
|
389 } |
|
390 |
|
391 delete iConsole; |
|
392 |
|
393 } |
|
394 |
|
395 /* |
|
396 ------------------------------------------------------------------------------- |
|
397 |
|
398 Class: CMenuDialog |
|
399 |
|
400 Method: Run1 |
|
401 |
|
402 Description: Callback function. Closes dialog |
|
403 |
|
404 Parameters: None |
|
405 |
|
406 Return Values: None |
|
407 |
|
408 Errors/Exceptions: None |
|
409 |
|
410 Status: Draft |
|
411 |
|
412 ------------------------------------------------------------------------------- |
|
413 */ |
|
414 void CMenuDialog::Run1() |
|
415 { |
|
416 |
|
417 if ( iCallBack2.isCompleted() ) |
|
418 { |
|
419 *iKeyCode = iConsole->KeyCode(); |
|
420 |
|
421 User::RequestComplete( iStatus, iCallBack2.Status().Int() ); |
|
422 } |
|
423 |
|
424 TInt index = iMain->iDialogs.Find( this ); |
|
425 if( index >= 0 ) |
|
426 { |
|
427 iMain->iDialogs.Remove( index ); |
|
428 } |
|
429 // Timeout, delete this object |
|
430 delete this; |
|
431 return; |
|
432 |
|
433 } |
|
434 |
|
435 |
|
436 /* |
|
437 ------------------------------------------------------------------------------- |
|
438 |
|
439 Class: CMenuDialog |
|
440 |
|
441 Method: WaitForKeypress |
|
442 |
|
443 Description: Wait for keypress |
|
444 |
|
445 Parameters: None |
|
446 |
|
447 Return Values: Symbian OS error code |
|
448 |
|
449 Errors/Exceptions: None |
|
450 |
|
451 Status: Draft |
|
452 |
|
453 ------------------------------------------------------------------------------- |
|
454 */ |
|
455 TInt CMenuDialog::WaitForKeypress( TKeyCode& aKeyCode, |
|
456 TRequestStatus& aStatus ) |
|
457 { |
|
458 |
|
459 aStatus = KRequestPending; |
|
460 iKeyCode = &aKeyCode; |
|
461 iStatus = &aStatus; |
|
462 |
|
463 CActiveScheduler::Add ( &iCallBack2 ); |
|
464 |
|
465 // Poll keypresses |
|
466 iConsole->Read( iCallBack2.Activate() ); |
|
467 |
|
468 return KErrNone; |
|
469 |
|
470 } |
|
471 |
|
472 // ================= OTHER EXPORTED FUNCTIONS ================================= |
|
473 |
|
474 // End of File |