applayerprotocols/ftpengine/consui/CONSOLE.CPP
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Author:	Philippe Gabriel
       
    15 // Console active object
       
    16 // Buffers input from the keyboard and reports a command line
       
    17 // terminated by a return key
       
    18 // 
       
    19 //
       
    20 
       
    21 /**
       
    22  @file Console.cpp
       
    23  @internalComponent
       
    24 */
       
    25 
       
    26 //#include "defs.h"
       
    27 //#include "debug.h"
       
    28 #include "CONSOLE.H"
       
    29 #include <e32base.h>
       
    30 #include <e32test.h>
       
    31 
       
    32 //
       
    33 // Definitions
       
    34 //
       
    35 
       
    36 CmdConsole::CmdConsole(MCmdConsoleReport* aNotifier,CConsoleBase* aConsole):CActive(CActive::EPriorityStandard),
       
    37 iNotifier(aNotifier),iConsole(aConsole),iAcceptInput(TRUE)
       
    38 {
       
    39 }
       
    40 
       
    41 CmdConsole* CmdConsole::NewL(MCmdConsoleReport* aNotifier,CConsoleBase* aConsole)
       
    42 {
       
    43 	CmdConsole* self = new(ELeave) CmdConsole(aNotifier,aConsole);
       
    44 	CActiveScheduler::Add(self);
       
    45 	return self;
       
    46 }
       
    47 
       
    48 CmdConsole::~CmdConsole(void)
       
    49 {
       
    50 Cancel();
       
    51 }
       
    52 
       
    53 void CmdConsole::Start(void)
       
    54 {
       
    55 	iConsole->Read(iStatus);
       
    56 	SetActive();
       
    57 }
       
    58 
       
    59 void CmdConsole::Reset(void)
       
    60 {
       
    61 	// Reset buffer
       
    62 	iCmdBuffer.Zero();
       
    63 	// Ok to Accept input
       
    64 	iAcceptInput = TRUE;
       
    65 	// Display a prompt
       
    66 	iConsole->Printf(_L("\nftp>"));
       
    67 }
       
    68 
       
    69 TDes& CmdConsole::FetchCmd(void)
       
    70 {
       
    71 	return iCmdBuffer;
       
    72 }
       
    73 
       
    74 void CmdConsole::RunL()
       
    75 {
       
    76 // Utput to the screen is done in a weird way
       
    77 // but could not find the pattern to printf directly
       
    78 TBuf<5> test;
       
    79 TPtrC acceptInput(KAlphabet);
       
    80 TChar c= iConsole->KeyCode();
       
    81 	Start();
       
    82 	if ( c == EKeyEscape )
       
    83 		{
       
    84 		// Call Notifier
       
    85 		iNotifier->Escape();
       
    86 		return;
       
    87 		}
       
    88 	if (!iAcceptInput)
       
    89 		return;
       
    90 	if ( c == EKeyEnter )
       
    91 		{
       
    92 		// Call Notifier
       
    93 		iAcceptInput = FALSE;
       
    94 		iConsole->Printf(_L("\n"));
       
    95 		iNotifier->CmdReady();
       
    96 		return;
       
    97 		}
       
    98 	if (c == EKeyBackspace) 
       
    99 		{if (iCmdBuffer.Length()==0)
       
   100 			// If buffer empty bail out
       
   101 			return;
       
   102 		// Otherwise remove last char from buffer
       
   103 		iCmdBuffer.Delete(iCmdBuffer.Length()-1,1);
       
   104 		test.Zero();
       
   105 		test.Append(EKeyBackspace);
       
   106 		test.Append(' ');
       
   107 		test.Append(EKeyBackspace);
       
   108 		test.Append(0);
       
   109 
       
   110 		iConsole->Printf(_L("%S"),&test);
       
   111 		//	iConsole->Printf(_L("%C"),c);
       
   112 		}
       
   113 	else if(KErrNotFound != acceptInput.Locate(c))
       
   114 		{
       
   115 		// Is that a char or a cmd?
       
   116 		// If it's a char append it 
       
   117 		iCmdBuffer.Append(c);
       
   118 		// Output it on the screen
       
   119 		// iConsole->Printf(_L("%S"),&acceptInput.Mid(acceptInput.Locate(c),1));
       
   120 		// iConsole->Printf(_L("%c"),c);
       
   121 		test.Zero();
       
   122 		test.Append(c);
       
   123 		test.Append(0);
       
   124 
       
   125 		iConsole->Printf(_L("%S"),&test);
       
   126 		}
       
   127 }
       
   128 
       
   129 void CmdConsole::DoCancel(void)
       
   130 {
       
   131 iConsole->ReadCancel();
       
   132 }
       
   133 
       
   134 void CmdConsole::ConstructL(void){}
       
   135