stif/TouchConsoleUI/src/ConsoleNotify.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     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     TSize size;
       
   118     iMain->GetConsole()->Size(size);
       
   119     
       
   120     size.iWidth = Min( size.iWidth - KMenuOverhead, 
       
   121                        aError.Length() );
       
   122     size.iHeight = aError.Length()/size.iWidth + 2;
       
   123     
       
   124     iConsole = Console::NewL( _L("Error note"), size );
       
   125     
       
   126     iConsole->Printf( _L("Error:") );    
       
   127     iConsole->Printf( aError ); 
       
   128     iConsole->Printf( _L("\n") );
       
   129     iConsole->Printf( _L("Press any key") );
       
   130 
       
   131     iTimer.CreateLocal();
       
   132 
       
   133     CActiveScheduler::Add ( &iCallBack1 );
       
   134     CActiveScheduler::Add ( &iCallBack2 );
       
   135 
       
   136     // Get timer
       
   137     iTimer.After( iCallBack1.Activate(), 10000000 );
       
   138 
       
   139     // Poll keypresses
       
   140     iConsole->Read ( iCallBack2.Activate() );        
       
   141 
       
   142     }
       
   143 
       
   144 /*
       
   145 -------------------------------------------------------------------------------
       
   146 
       
   147     Class: CMenuNotifier
       
   148 
       
   149     Method: CMenuNotifier
       
   150 
       
   151     Description: Constructor
       
   152 
       
   153     Parameters: None
       
   154 
       
   155     Return Values: None
       
   156 
       
   157     Errors/Exceptions: None
       
   158 
       
   159     Status: Draft
       
   160 
       
   161 -------------------------------------------------------------------------------
       
   162 */
       
   163 #pragma warning( disable : 4355 )       // Incomplete this usage
       
   164 CMenuNotifier::CMenuNotifier( CConsoleMain* aMain ): 
       
   165     iCallBack1 ( this, GETPTR CMenuNotifier::Run1 ),
       
   166     iCallBack2 ( this, GETPTR CMenuNotifier::Run1 ),
       
   167     iMain( aMain )          
       
   168     {
       
   169     }
       
   170 #pragma warning( default : 4355 )
       
   171 
       
   172 /*
       
   173 -------------------------------------------------------------------------------
       
   174 e
       
   175     Class: CMenuNotifier
       
   176 
       
   177     Method: ~CMenuNotifier
       
   178 
       
   179     Description: Destructor
       
   180 
       
   181     Parameters: None
       
   182 
       
   183     Return Values: None
       
   184 
       
   185     Errors/Exceptions: None
       
   186 
       
   187     Status: Draft
       
   188     
       
   189 -------------------------------------------------------------------------------
       
   190 */
       
   191 CMenuNotifier::~CMenuNotifier()
       
   192     {
       
   193 
       
   194     delete iConsole;    
       
   195 
       
   196     }
       
   197 
       
   198 
       
   199 
       
   200 /*
       
   201 -------------------------------------------------------------------------------
       
   202 
       
   203     Class: CMenuNotifier
       
   204 
       
   205     Method: Run1
       
   206 
       
   207     Description: Callback function. Closes dialog
       
   208 
       
   209     Parameters: None
       
   210 
       
   211     Return Values: None
       
   212 
       
   213     Errors/Exceptions: None
       
   214 
       
   215     Status: Draft
       
   216     
       
   217 -------------------------------------------------------------------------------
       
   218 */
       
   219 void CMenuNotifier::Run1()
       
   220     {
       
   221 
       
   222     if ( iCallBack1.isCompleted() && iCallBack2.isCompleted() )
       
   223         {
       
   224         // Both callback have been done, delete this object
       
   225         delete this;
       
   226         return;
       
   227         }
       
   228     else
       
   229         {
       
   230         // One callback finished, stop listening anything else
       
   231         iConsole->ReadCancel();
       
   232         iTimer.Cancel();
       
   233         }
       
   234     }  
       
   235 
       
   236 
       
   237 // ================= MEMBER FUNCTIONS =========================================
       
   238 
       
   239 /*
       
   240 -------------------------------------------------------------------------------
       
   241 
       
   242     Class: CMenuDialog
       
   243 
       
   244     Method: NewL
       
   245 
       
   246     Description: Constructs new menu dialog
       
   247 
       
   248     Parameters: const TDesC& aMessage: in: Message to dialog
       
   249 
       
   250     Return Values: CMenu*                           New menu
       
   251 
       
   252     Errors/Exceptions: Leaves if memory allocation fails
       
   253                        Leaves if ConstructL leaves.
       
   254 
       
   255     Status: Draft
       
   256 
       
   257 -------------------------------------------------------------------------------
       
   258 */
       
   259 CMenuDialog* CMenuDialog::NewL( CConsoleMain* aMain,
       
   260                                 const TDesC& aLine1, 
       
   261                                 const TDesC& aLine2, 
       
   262                                 TInt aTimeInSecs )
       
   263     {
       
   264 
       
   265     CMenuDialog* self = new ( ELeave ) CMenuDialog( aMain );
       
   266     CleanupStack::PushL( self );
       
   267     self->ConstructL( aLine1, aLine2, aTimeInSecs );
       
   268     CleanupStack::Pop( self );
       
   269     return self;
       
   270 
       
   271     }
       
   272 
       
   273 
       
   274 /*
       
   275 -------------------------------------------------------------------------------
       
   276 
       
   277     Class: CMenuDialog
       
   278 
       
   279     Method: ConstructL
       
   280 
       
   281     Description: Second level constructor.
       
   282 
       
   283     Parameters: const TDesC& aMessage: in: Message to dialog
       
   284     
       
   285     Return Values: None
       
   286 
       
   287     Errors/Exceptions: None
       
   288 
       
   289     Status: Draft
       
   290 
       
   291 -------------------------------------------------------------------------------
       
   292 */
       
   293 void CMenuDialog::ConstructL( const TDesC& aLine1, 
       
   294                               const TDesC& aLine2, 
       
   295                               TInt aTimeInSecs )
       
   296     {
       
   297     
       
   298     //TSize size = iMain->GetConsole()->ScreenSize();
       
   299     TSize size;
       
   300     iMain->GetConsole()->Size(size);
       
   301     
       
   302     size.iWidth = Min( size.iWidth - KMenuOverhead, 
       
   303                        Max( aLine1.Length(), aLine2.Length() ) );
       
   304     size.iHeight = aLine1.Length()/size.iWidth + aLine2.Length()/size.iWidth + 2;
       
   305     
       
   306     iConsole = Console::NewL( _L("Info"), size );
       
   307     
       
   308     if( aLine1.Length() > 0 )
       
   309         {
       
   310         iConsole->Printf( aLine1 );
       
   311         }
       
   312     if( aLine2.Length() > 0 )
       
   313         {
       
   314         iConsole->Printf( _L("\n") );
       
   315         iConsole->Printf( aLine2 );
       
   316         }
       
   317     
       
   318     if( aTimeInSecs == 0 )
       
   319         {
       
   320         aTimeInSecs = KDefaultTime;
       
   321         }
       
   322     iTimer.CreateLocal();
       
   323 
       
   324     CActiveScheduler::Add ( &iCallBack1 );
       
   325     // Get timer
       
   326     iTimer.After( iCallBack1.Activate(), aTimeInSecs*1000*1000 );
       
   327            
       
   328     }
       
   329 
       
   330 /*
       
   331 -------------------------------------------------------------------------------
       
   332 
       
   333     Class: CMenuDialog
       
   334 
       
   335     Method: CMenuDialog
       
   336 
       
   337     Description: Constructor
       
   338 
       
   339     Parameters: None
       
   340 
       
   341     Return Values: None
       
   342 
       
   343     Errors/Exceptions: None
       
   344 
       
   345     Status: Draft
       
   346 
       
   347 -------------------------------------------------------------------------------
       
   348 */
       
   349 #pragma warning( disable : 4355 )       // Incomplete this usage
       
   350 CMenuDialog::CMenuDialog( CConsoleMain* aMain ):  
       
   351     iMain( aMain ),      
       
   352     iCallBack1 ( this, GETPTR CMenuDialog::Run1 ), 
       
   353     iCallBack2 ( this, GETPTR CMenuDialog::Run1 )
       
   354     {
       
   355     }
       
   356 #pragma warning( default : 4355 )
       
   357 
       
   358 /*
       
   359 -------------------------------------------------------------------------------
       
   360 e
       
   361     Class: CMenuDialog
       
   362 
       
   363     Method: ~CMenuDialog
       
   364 
       
   365     Description: Destructor
       
   366 
       
   367     Parameters: None
       
   368 
       
   369     Return Values: None
       
   370 
       
   371     Errors/Exceptions: None
       
   372 
       
   373     Status: Draft
       
   374     
       
   375 -------------------------------------------------------------------------------
       
   376 */
       
   377 CMenuDialog::~CMenuDialog()
       
   378     {
       
   379  
       
   380     if( iCallBack1.IsActive() )
       
   381         {
       
   382         iTimer.Cancel();
       
   383         iTimer.Close();
       
   384         iCallBack1.Cancel();
       
   385         }
       
   386         
       
   387     if( iCallBack2.IsActive() )
       
   388         {
       
   389         User::RequestComplete( iStatus, KErrCancel );
       
   390 		if( iConsole != NULL )
       
   391 			{
       
   392 			iConsole->ReadCancel();    
       
   393 			}
       
   394         iCallBack2.Cancel();
       
   395         }
       
   396         
       
   397     delete iConsole;    
       
   398 
       
   399     }
       
   400 
       
   401 /*
       
   402 -------------------------------------------------------------------------------
       
   403 
       
   404     Class: CMenuDialog
       
   405 
       
   406     Method: Run1
       
   407 
       
   408     Description: Callback function. Closes dialog
       
   409 
       
   410     Parameters: None
       
   411 
       
   412     Return Values: None
       
   413 
       
   414     Errors/Exceptions: None
       
   415 
       
   416     Status: Draft
       
   417     
       
   418 -------------------------------------------------------------------------------
       
   419 */
       
   420 void CMenuDialog::Run1()
       
   421     {
       
   422 
       
   423     if ( iCallBack2.isCompleted() )
       
   424         {            
       
   425         *iKeyCode = iConsole->KeyCode();
       
   426     
       
   427         User::RequestComplete( iStatus, iCallBack2.Status().Int() );
       
   428         }
       
   429         
       
   430     TInt index = iMain->iDialogs.Find( this );
       
   431     if( index >= 0 )
       
   432         {
       
   433         iMain->iDialogs.Remove( index );
       
   434         }
       
   435     // Timeout, delete this object
       
   436     delete this;
       
   437     return;
       
   438 
       
   439     }  
       
   440 
       
   441 
       
   442 /*
       
   443 -------------------------------------------------------------------------------
       
   444 
       
   445     Class: CMenuDialog
       
   446 
       
   447     Method: WaitForKeypress
       
   448 
       
   449     Description: Wait for keypress
       
   450 
       
   451     Parameters: None
       
   452 
       
   453     Return Values: Symbian OS error code
       
   454 
       
   455     Errors/Exceptions: None
       
   456 
       
   457     Status: Draft
       
   458     
       
   459 -------------------------------------------------------------------------------
       
   460 */
       
   461 TInt CMenuDialog::WaitForKeypress( TKeyCode& aKeyCode, 
       
   462                                    TRequestStatus& aStatus )
       
   463     {
       
   464     
       
   465     aStatus = KRequestPending;
       
   466     iKeyCode = &aKeyCode;
       
   467     iStatus = &aStatus;
       
   468     
       
   469     CActiveScheduler::Add ( &iCallBack2 );
       
   470      
       
   471     // Poll keypresses
       
   472     iConsole->Read( iCallBack2.Activate() );        
       
   473 
       
   474     return KErrNone;
       
   475     
       
   476     }  
       
   477 
       
   478 // ================= OTHER EXPORTED FUNCTIONS =================================
       
   479 
       
   480 // End of File