📄 puttyappui.cpp
字号:
/* puttyappui.cpp * * Putty UI Application UI class * * Copyright 2003-2004 Sergei Khloupnov * Copyright 2002-2004 Petteri Kangaslampi * * See license.txt for full copyright and license information.*/#include <aknquerydialog.h>#include <aknnotedialog.h>#include <aknnotewrappers.h>#include <stringloader.h>#include <aknmessagequerydialog.h>#include <aknwaitdialog.h>#include <eikenv.h>#include <eikon.hrh>#include <es_sock.h>#include <eikmenup.h>#include <akndoc.h>#include <aknapp.h>#include <apgwgnam.h>#include <apgtask.h>#include <coeutils.h>#include "filelistdialog.h"#include "puttyappui.h"#include "puttyterminalview.h"#include "puttyengine.h"#include "puttyui.hrh"#include <putty.rsg>extern "C" {#include "putty.h"}const TInt KInitAudioLength = 32000;const TInt KExitReason = -1;_LIT(KAssertPanic, "puttyappui.cpp");#define assert(x) __ASSERT_ALWAYS(x, User::Panic(KAssertPanic, __LINE__))_LIT(KRandomFile,"random.dat");_LIT(KDefaultSettingsFile, "defaults");_LIT(KFontDir, "fonts");_LIT(KFontExtension, ".s2f");_LIT(KDefaultFont, "fixed5x7");#ifdef __WINS___LIT(KPuttyEngine, "puttyengine.dll");_LIT(KTempParamFile, "c:\\puttystarttemp");#else_LIT(KPuttyEngine, "puttyengine.exe");#endif#ifdef EKA2// FIXME: Use data caging directories!_LIT(KDataDir, "\\system\\apps\\putty\\");#endif//_LIT8(KFontNameLabel, "%s %d");static const TInt KFullScreen = 0xf5;//#include <e32svr.h>//#define DEBUGPRINT(x) RDebug::Print x#define DEBUGPRINT(x)CPuttyAppUi::CPuttyAppUi()#ifndef PUTTY_NO_AUDIORECORDER : iAudioRecordDes(NULL, 0, 0)#endif{ iTermWidth = 80; iTermHeight = 24;}void CPuttyAppUi::ConstructL() { CEikonEnv::Static()->DisableExitChecks(ETrue); BaseConstructL(); iFatalErrorPanic = CEikonEnv::Static()->AllocReadResourceL(R_STR_FATAL_ERROR); iConnectedMsg = CEikonEnv::Static()->AllocReadResourceL(R_STR_CONNECTING_TO_HOST); iDialer = CDialer::NewL(this);#ifndef PUTTY_NO_AUDIORECORDER iRecorder = CAudioRecorder::NewL(this);#endif // Determine application installation path HBufC *appDll = HBufC::NewLC(KMaxFileName); *appDll = iDocument->Application()->AppFullName(); TParse parsa; User::LeaveIfError(parsa.SetNoWild(*appDll, NULL, NULL));#ifdef EKA2 iDataPath = parsa.Drive(); iDataPath.Append(KDataDir);#else iDataPath = parsa.DriveAndPath();#endif CleanupStack::PopAndDestroy(); // appDll // If the application is in ROM (drive Z:), put settings on C: if ( (iDataPath[0] == 'Z') || (iDataPath[0] == 'z') ) { iDataPath[0] = 'C'; } // Make sure the path ends with a backslash if ( iDataPath[iDataPath.Length()-1] != '\\' ) { iDataPath.Append('\\'); } DEBUGPRINT((_L("ProcessCommandParametersL: iDataPath = %S"), &iDataPath)); iFontPath = iDataPath; iFontPath.Append(KFontDir); iFontPath.Append('\\'); // Check if the random seed already exists. If not, we are probably running // PuTTY for the first time and the generator should be seeded. // We'll need to check this before initializing the engine, since it will // create the file at startup. HBufC *seedFileBuf = HBufC::NewLC(KMaxFileName); TPtr seedFile = seedFileBuf->Des(); seedFile = iDataPath; seedFile.Append(KRandomFile); iRandomExists = ConeUtils::FileExists(seedFile); CleanupStack::PopAndDestroy(seedFileBuf); // Create and initialize the engine iEngine = CPuttyEngine::NewL(this, iDataPath); iEngine->SetTerminalSize(iTermWidth, iTermHeight); // Check if the default settings file exists. If yes, read it, otherwise // create one HBufC *settingsFileBuf = HBufC::NewLC(KMaxFileName); TPtr settingsFile = settingsFileBuf->Des(); settingsFile = iDataPath; settingsFile.Append(KDefaultSettingsFile); if ( ConeUtils::FileExists(settingsFile) ) { iEngine->ReadConfigFileL(settingsFile); ReadUiSettingsL(iEngine->GetConfig()); } else { iEngine->SetDefaults(); iFontName = KDefaultFont; WriteUiSettingsL(iEngine->GetConfig()); iEngine->WriteConfigFileL(settingsFile); } CleanupStack::PopAndDestroy(); //settingsFileBuf; // Build a list of possible fonts CDir *dir; User::LeaveIfError( CEikonEnv::Static()->FsSession().GetDir( iFontPath, KEntryAttNormal, ESortByName, dir)); CleanupStack::PushL(dir); iNumFonts = dir->Count(); iFonts = new (ELeave) HBufC*[iNumFonts]; Mem::FillZ((TAny*)iFonts, iNumFonts*sizeof(HBufC*)); for ( TInt i = 0; i < iNumFonts; i++ ) { parsa.SetNoWild((*dir)[i].iName, NULL, NULL); iFonts[i] = HBufC::NewL(parsa.Name().Length()); *iFonts[i] = parsa.Name(); } CleanupStack::PopAndDestroy(); //dir // Build the terminal view HBufC *fontFileBuf = HBufC::NewLC(KMaxFileName); TPtr fontFile = fontFileBuf->Des(); fontFile = iFontPath; fontFile.Append(iFontName); fontFile.Append(KFontExtension); iTerminalView = CPuttyTerminalView::NewL(this, this, fontFile); AddViewL(iTerminalView); // takes ownership SetDefaultViewL(*iTerminalView); CleanupStack::PopAndDestroy(); //fontFileBuf; // Engine initialization will be completed once the terminal has // been created. See TerminalCreatedL().}CPuttyAppUi::~CPuttyAppUi() { if ( iFonts ) { for ( TInt i = 0; i < iNumFonts; i++ ) { delete iFonts[i]; } delete iFonts; } #ifndef PUTTY_NO_AUDIORECORDER delete iRecorder; delete iAudio;#endif delete iDialer; delete iEngine; delete iConnectedMsg; delete iFatalErrorPanic;}CPuttyEngine* CPuttyAppUi::Engine() { return iEngine;}// Displays information notevoid ShowInformationNoteL(TInt aResourceId) { CEikonEnv *eenv = CEikonEnv::Static(); CAknInformationNote* dlg = new (ELeave) CAknInformationNote(); dlg->ExecuteLD(eenv->AllocReadResourceLC(aResourceId)->Des()); CleanupStack::PopAndDestroy(); // allocated string}TBool CPuttyAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName & aDocumentName, const TDesC8 &aTail) { // If we got a config file as a parameter, read it if ( aCommand == EApaCommandOpen ) { DEBUGPRINT((_L("ProcessCommandParametersL: Reading config file"))); iEngine->ReadConfigFileL(aDocumentName); } // Final hack, keep the system happy. This is necessary since we aren't // really a proper file-based application. DEBUGPRINT((_L("ProcessCommandParametersL: Init done"))); return CEikAppUi::ProcessCommandParametersL(aCommand, aDocumentName, aTail);}TKeyResponse CPuttyAppUi::HandleKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/ ) { return EKeyWasNotConsumed;}void CPuttyAppUi::TerminalCreatedL() { // Terminal has been created. Finish up initialization iTerminal = iTerminalView->Terminal(); iTerminalView->SetTerminalGrayed(ETrue); iLastCommand = EPuttyCmdConnectionConnect; // Initialize the random number generator if necessary#ifndef PUTTY_NO_AUDIORECORDER if ( !iRandomExists ) { DEBUGPRINT((_L("ProcessCommandParametersL: Initializing random number generator"))); if ( CAknQueryDialog::NewL()->ExecuteLD( R_INITIAL_RNG_INIT_CONFIRMATION) ) { HandleCommandL(EPuttyCmdInitRandomGenerator); } }#endif}void CPuttyAppUi::TerminalDeleted() { // Terminal has been deleted iTerminal = NULL;}void CPuttyAppUi::HandleCommandL(TInt aCommand) { TInt saveLastCommand = iLastCommand; // Repeat only commands with ID below EPuttyCmdNotRepeated if( aCommand < EPuttyCmdNotRepeated ) { iLastCommand = aCommand; } Config * config = iEngine->GetConfig(); // assume there are not more than 100 fonts available // this is to not confuse font select cmd with Exit or other // pre-defined system commands if ( (aCommand >= EPuttyCmdSetFont) && (aCommand < (EPuttyCmdSetFont + 100)) ) { assert((aCommand-EPuttyCmdSetFont) < iNumFonts); iFontName = *iFonts[aCommand-EPuttyCmdSetFont]; TFileName fontFile; fontFile = iFontPath; fontFile.Append(iFontName); fontFile.Append(KFontExtension); iTerminalView->SetFontL(fontFile); return; } HBufC* text; // will use with StringLoader HBufC *buf = HBufC::NewLC(256); TPtr ptr = buf->Des(); switch (aCommand) { case EPuttyCmdRepeatLast: { iLastCommand = saveLastCommand; if ( iLastCommand < EPuttyCmdNotRepeated ) { HandleCommandL(iLastCommand); } break; } case EPuttyCmdConnectionConnect: { if ( iState != EPuttyUIStateNone ) { ShowInformationNoteL(R_STR_CONNECTION_IN_PROGRESS); break; } assert(iEngine); StringToDes(config->host, ptr); text = StringLoader::LoadLC(R_STRING_HOST); CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog(ptr); dlg->SetPromptL(*text); dlg->PrepareLC(R_SETTINGS_STRING_ENTRY); dlg->SetMaxLength(128); if ( dlg->RunLD() ) { DesToString(ptr, config->host, sizeof(config->host)); iState = EPuttyUIStateDialing; ShowDialWaitDialogL(); iDialer->DialL(); } CleanupStack::PopAndDestroy(); // text break; } case EPuttyCmdConnectionClose: { iDialer->CancelDialL(); break; } case EPuttyCmdConnectionDisconnect: { iEngine->Disconnect(); assert(iTerminal); iTerminalView->SetTerminalGrayed(ETrue); iState = EPuttyUIStateDisconnected; iDialer->CloseConnectionL(); break; } case EPuttyCmdReverseScreen: { assert(iTerminal); // FIXME: saved in try_palette field if( config->try_palette ) {// iTerminal->SetReverse(EFalse); config->try_palette = 0; } else {// iTerminal->SetReverse(ETrue); config->try_palette = 1; } break; } case EPuttyCmdFullScreen: { if ( iFullScreen ) { iFullScreen = EFalse; } else { iFullScreen = ETrue; } iTerminalView->SetFullScreenL(iFullScreen); break; } case EPuttyCmdInitRandomGenerator: {#ifndef PUTTY_NO_AUDIORECORDER if ( iRecording ) { ShowInformationNoteL(R_STR_RECORDING_IN_PROGRESS); break; } if( CAknQueryDialog::NewL()->ExecuteLD(R_RECORD_CONFIRMATION) ) { delete iAudio; iAudio = NULL; iAudio = HBufC8::NewL(KInitAudioLength); iAudioRecordDes.Set(iAudio->Des()); iRecorder->RecordL(iAudioRecordDes); iRecording = ETrue; ShowRecordWaitDialogL(); }#endif break; } case EPuttyCmdSettingsConnectionHostPort: { assert(iState == EPuttyUIStateNone); StringToDes(config->host, ptr); CAknMultiLineDataQueryDialog* dlg = CAknMultiLineDataQueryDialog::NewL(ptr, config->port); if( dlg->ExecuteLD(R_SETTINGS_HOST_PORT_ENTRY) ) { DesToString(ptr, config->host, sizeof(config->host)); } break; } case EPuttyCmdSettingsConnectionVersion: { assert(iState == EPuttyUIStateNone); assert((config->sshprot >= 0) && (config->sshprot <= 3)); TInt index(config->sshprot); CAknListQueryDialog *dlg = new (ELeave) CAknListQueryDialog(&index ); if ( dlg->ExecuteLD( R_SETTINGS_PROTOCOL ) ) { config->sshprot = index; } break; } case EPuttyCmdSettingsAuthenticationUsername: { assert(iState == EPuttyUIStateNone); StringToDes(config->username, ptr); CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog(ptr); text = StringLoader::LoadLC(R_STRING_USERNAME); dlg->SetPromptL(text->Des()); if( dlg->ExecuteLD(R_SETTINGS_STRING_ENTRY) ) { DesToString(ptr, config->username, sizeof(config->username)); } CleanupStack::PopAndDestroy(); // text break; } case EPuttyCmdSettingsAuthenticationKeyfile: {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -