⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 puttyappui.cpp

📁 大名鼎鼎的远程登录软件putty的Symbian版源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*    puttyappui.cpp * * Putty UI Application UI class * * Copyright 2002,2003 Petteri Kangaslampi * * See license.txt for full copyright and license information.*/#include <eikenv.h>#include <eikon.hrh>#include <ckninfo.h>#include <cknconf.h>#include <es_sock.h>#include <eikmenup.h>#include <eikdoc.h>#include <ckndgopn.h>#include <ckndgsve.h>#include <eikmisdg.h>#include <eikapp.h>#include <apgwgnam.h>#include <apgtask.h>#include "puttyappui.h"#include "puttyappview.h"#include "puttyengine.h"#include "puttyui.hrh"#include "connectiondialog.h"#include "settingsdialog.h"#include "authdialog.h"#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");#ifdef __WINS___LIT(KPuttyEngine, "puttyengine.dll");_LIT(KTempParamFile, "c:\\puttystarttemp");#else_LIT(KPuttyEngine, "puttyengine.exe");#endif_LIT8(KSmallFontName, "small");_LIT8(KLargeFontName, "large");static const TInt KNormalSmallWidth = 80;static const TInt KNormalSmallHeight = 24;static const TInt KNormalLargeWidth = 74;static const TInt KNormalLargeHeight = 14;static const TInt KFullSmallWidth = 106;static const TInt KFullSmallHeight = 25;static const TInt KFullLargeWidth = 91;static const TInt KFullLargeHeight = 14;//#include <e32svr.h>//#define DEBUGPRINT(x) RDebug::Print x#define DEBUGPRINT(x)CPuttyAppUi::CPuttyAppUi() : iAudioRecordDes(NULL, 0, 0) {    iTermWidth = 80;    iTermHeight = 24;    iLargeFont = EFalse;}void CPuttyAppUi::ConstructL() {    CEikonEnv::Static()->DisableExitChecks(ETrue);    BaseConstructL();    iFatalErrorPanic =        CEikonEnv::Static()->AllocReadResourceL(R_STR_FATAL_ERROR);    iDialler = CDialler::NewL(this);    iRecorder = CAudioRecorder::NewL(this);        // Determine application installation path    HBufC *appDll = HBufC::NewLC(KMaxFileName);    *appDll = iDocument->Application()->AppFullName();    TParse parsa;    User::LeaveIfError(parsa.SetNoWild(*appDll, NULL, NULL));    iInstallPath = parsa.DriveAndPath();    iDataPath = iInstallPath;    // 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));    // Build the terminal view    iAppView = new (ELeave) CPuttyAppView(this, this);    iAppView->ConstructL(iInstallPath, ClientRect());    AddToStackL(iAppView);    iAppView->Terminal()->SetGrayed(ETrue);    // 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);    TBool randomExists = EFalse;    TEntry dummy;    if ( CEikonEnv::Static()->FsSession().Entry(seedFile, dummy)         == KErrNone ) {        randomExists = ETrue;    }        // 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 ( CEikonEnv::Static()->FsSession().Entry(settingsFile, dummy)         == KErrNone ) {        iEngine->ReadConfigFileL(settingsFile);        ReadUiSettingsL(iEngine->GetConfig());    } else {        iEngine->SetDefaults();        iEngine->WriteConfigFileL(settingsFile);    }            // Initialize the random number generator if necessary    if ( !randomExists ) {                DEBUGPRINT((_L("ProcessCommandParametersL: Initializing random number generator")));        if ( CCknConfirmationDialog::RunDlgLD(R_STR_INITIAL_RANDOM_TITLE,                                              R_STR_INITIAL_RANDOM_TEXT,                                              NULL,                                              R_STR_OK_CONFIRM) ) {            HandleCommandL(ECmdInitRandomGenerator);        }    }    CleanupStack::PopAndDestroy(3); // appDll, settingsFileBuf, seedFileBuf}CPuttyAppUi::~CPuttyAppUi() {    if ( iAppView ) {        RemoveFromStack(iAppView);    }    delete iAppView;    delete iRecorder;    delete iAudio;    delete iDialler;    delete iEngine;    delete iFatalErrorPanic;}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);    } else {        // Try to load default settings            }    // 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);}void CPuttyAppUi::HandleCommandL(TInt aCommand) {    switch (aCommand) {        case ECmdConnect: {            if ( iState != EStateNone ) {                break;            }            assert(iEngine);            Config *cfg = iEngine->GetConfig();            THostName hostName;            char *c = cfg->host;            while ( *c ) {                hostName.Append(*c++);            }                        CConnectionDialog *dlg = new (ELeave) CConnectionDialog(hostName);                        if ( dlg->ExecuteLD(R_CONNECTION_DIALOG)) {                c = cfg->host;                for ( TInt i = 0; i < hostName.Length(); i++ ) {                    *c++ = (char) hostName[i];                }                *c++ = 0;                TRAPD(error, CEikonEnv::Static()->BusyMsgL(R_STR_DIALING));                iState = EStateDialing;                iDialler->DialL();            }            break;        }        case ECmdLargeFont: {            if ( iLargeFont ) {                iLargeFont = EFalse;            } else {                iLargeFont = ETrue;            }            iAppView->SetFontL(iLargeFont);            break;        }                case ECmdFullScreen: {            if ( iFullScreen ) {                iFullScreen = EFalse;            } else {                iFullScreen = ETrue;            }            iAppView->SetFullScreenL(iFullScreen);            break;        }        case ECmdInitRandomGenerator: {            if ( iRecording ) {                break;            }                        if ( CCknConfirmationDialog::RunDlgLD(R_STR_RECORD_CONFIRM_TITLE,                                                  R_STR_RECORD_CONFIRM_TEXT,                                                  NULL,                                                  R_STR_OK_CONFIRM) ) {                delete iAudio;                iAudio = NULL;                iAudio = HBufC8::NewL(KInitAudioLength);                iAudioRecordDes.Set(iAudio->Des());                iRecorder->RecordL(iAudioRecordDes);                iRecording = ETrue;                CEikonEnv::Static()->BusyMsgL(R_STR_RECORDING);            }                        break;        }        case ECmdSettings: {            assert(iState == EStateNone);            CSettingsDialog *dlg =                new (ELeave) CSettingsDialog(iEngine->GetConfig());            dlg->ExecuteLD(R_SETTINGS_DIALOG);            break;        }        case ECmdLoadSettings: {            assert(iState == EStateNone);            TFileName fileName;            TUid uid = { 0x101f9075 };            if ( CCknOpenFileDialog::RunDlgLD(                     fileName,                     R_STR_SHOW_PUTTY_CONFIG_FILES,                     CCknFileListDialogBase::EShowAllDrives,                     uid) ) {                iEngine->ReadConfigFileL(fileName);                ReadUiSettingsL(iEngine->GetConfig());            }            break;        }        case ECmdSaveSettings: {            assert(iState == EStateNone);            TFileName fileName;            if ( CCknSaveAsFileDialog::RunDlgLD(fileName) ) {                WriteUiSettingsL(iEngine->GetConfig());                iEngine->WriteConfigFileL(fileName);            }            break;        }        case ECmdSendSpecialCharacter:            if ( iState == EStateConnected ) {                CEikCharMapDialog::RunDlgLD(iAppView->Terminal());            }            break;        case ECmdSendPipe:            if ( iState == EStateConnected ) {                iEngine->SendKeypress((TKeyCode)'|', 0);            }            break;                        case ECmdSendBackquote:            if ( iState == EStateConnected ) {                iEngine->SendKeypress((TKeyCode)'`', 0);            }            break;        case ECmdSendF1:        case ECmdSendF2:        case ECmdSendF3:        case ECmdSendF4:        case ECmdSendF5:        case ECmdSendF6:        case ECmdSendF7:        case ECmdSendF8:        case ECmdSendF9:        case ECmdSendF10:            if ( iState == EStateConnected ) {                iEngine->SendKeypress(                    (TKeyCode) (EKeyF1 + (aCommand - ECmdSendF1)), 0);            }            break;        case ECmdSaveSettingsAsDefault: {            TFileName fileName;            fileName = iDataPath;            fileName.Append(KDefaultSettingsFile);            WriteUiSettingsL(iEngine->GetConfig());            iEngine->WriteConfigFileL(fileName);            break;        }        case ECmdResetDefaultSettings: {            iEngine->SetDefaults();            ReadUiSettingsL(iEngine->GetConfig());            HandleCommandL(ECmdSaveSettingsAsDefault);            break;        }        case ECmdAbout: {            CCknInfoDialog::RunDlgLD(                *CEikonEnv::Static()->AllocReadResourceLC(R_STR_ABOUT_TITLE),                *CEikonEnv::Static()->AllocReadResourceLC(R_STR_ABOUT_TEXT));            CleanupStack::PopAndDestroy(2); // title, text            break;        }                	case EEikCmdExit:             Exit();            break;    }    }void CPuttyAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane *aMenuPane) {            if ( aResourceId == R_PUTTY_VIEW_MENU ) {        if ( iLargeFont ) {            aMenuPane->SetItemButtonState(ECmdLargeFont, EEikMenuItemSymbolOn);        } else {            aMenuPane->SetItemButtonState(ECmdLargeFont,                                          EEikMenuItemSymbolIndeterminate);        }                if ( iFullScreen ) {            aMenuPane->SetItemButtonState(ECmdFullScreen,                                          EEikMenuItemSymbolOn);        } else {            aMenuPane->SetItemButtonState(ECmdFullScreen,                                          EEikMenuItemSymbolIndeterminate);        }            } else if ( aResourceId == R_PUTTY_SETTINGS_MENU ) {        aMenuPane->SetItemDimmed(ECmdLoadSettings, (iState != EStateNone));        aMenuPane->SetItemDimmed(ECmdSettings, (iState != EStateNone));        aMenuPane->SetItemDimmed(ECmdSaveSettings, (iState != EStateNone));        aMenuPane->SetItemDimmed(ECmdSaveSettingsAsDefault,                                 (iState != EStateNone));        aMenuPane->SetItemDimmed(ECmdResetDefaultSettings,                                 (iState != EStateNone));            } else if ( aResourceId == R_PUTTY_TOOLS_MENU ) {        aMenuPane->SetItemDimmed(ECmdSendSpecialCharacter,                                 (iState != EStateConnected));            } else if ( aResourceId == R_PUTTY_SEND_CHARACTER_MENU ) {        aMenuPane->SetItemDimmed(ECmdSendPipe,                                 (iState != EStateConnected));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -