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

📄 puttyappui.cpp

📁 大名鼎鼎的远程登录软件putty的Symbian版源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void CPuttyAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane *aMenuPane) {    if ( aResourceId == R_PUTTY_EDIT_MENU ) {        if ( iState == EStateConnected ) {            aMenuPane->SetItemDimmed(ECmdSelect, EFalse);            aMenuPane->SetItemDimmed(ECmdMark, !iSelectMode);            aMenuPane->SetItemDimmed(ECmdCopy, !iHaveMark);            aMenuPane->SetItemDimmed(ECmdPaste, EFalse);            if ( iSelectMode ) {                aMenuPane->SetItemButtonState(ECmdSelect,                                              EEikMenuItemSymbolOn);            } else {                aMenuPane->SetItemButtonState(ECmdSelect,                                              EEikMenuItemSymbolIndeterminate);            }                    } else {            aMenuPane->SetItemDimmed(ECmdSelect, ETrue);            aMenuPane->SetItemDimmed(ECmdMark, ETrue);            aMenuPane->SetItemDimmed(ECmdCopy, ETrue);            aMenuPane->SetItemDimmed(ECmdPaste, ETrue);        }                    } else 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));        aMenuPane->SetItemDimmed(ECmdSendBackquote,                                 (iState != EStateConnected));            } else if ( aResourceId == R_PUTTY_SEND_FUNCTION_KEY_MENU ) {        TBool dimmed = (iState != EStateConnected);        aMenuPane->SetItemDimmed(ECmdSendF1, dimmed);        aMenuPane->SetItemDimmed(ECmdSendF2, dimmed);        aMenuPane->SetItemDimmed(ECmdSendF3, dimmed);        aMenuPane->SetItemDimmed(ECmdSendF4, dimmed);        aMenuPane->SetItemDimmed(ECmdSendF5, dimmed);        aMenuPane->SetItemDimmed(ECmdSendF6, dimmed);        aMenuPane->SetItemDimmed(ECmdSendF7, dimmed);        aMenuPane->SetItemDimmed(ECmdSendF8, dimmed);        aMenuPane->SetItemDimmed(ECmdSendF9, dimmed);        aMenuPane->SetItemDimmed(ECmdSendF10, dimmed);    }}// Reads the UI settings (font size, full screen flag) from a config structurevoid CPuttyAppUi::ReadUiSettingsL(Config *aConfig) {    TPtrC8 fontDes((const TUint8*)aConfig->font.name);    if ( fontDes.CompareF(KLargeFontName) == 0 ) {        iLargeFont = ETrue;    } else {        iLargeFont = EFalse;    }    iAppView->SetFontL(iLargeFont);    if ( iLargeFont ) {        if ( (aConfig->width == KFullLargeWidth) &&             (aConfig->height == KFullLargeHeight) ) {            iFullScreen = ETrue;        } else {            iFullScreen = EFalse;        }    } else {        if ( (aConfig->width == KFullSmallWidth) &&             (aConfig->height == KFullSmallHeight) ) {            iFullScreen = ETrue;        } else {            iFullScreen = EFalse;        }    }    iAppView->SetFullScreenL(iFullScreen);}// Writes the UI settings (font size, full screen flag) to a config structurevoid CPuttyAppUi::WriteUiSettingsL(Config *aConfig) {    TPtr8 fontPtr((TUint8*)aConfig->font.name, sizeof(aConfig->font.name));    if ( iLargeFont ) {        fontPtr = KLargeFontName;    } else {        fontPtr = KSmallFontName;    }    fontPtr.Append('\0');    if ( iLargeFont ) {        if ( iFullScreen ) {            aConfig->width = KFullLargeWidth;            aConfig->height = KFullLargeHeight;        } else {            aConfig->width = KNormalLargeWidth;            aConfig->height = KNormalLargeHeight;        }    } else {        if ( iFullScreen ) {            aConfig->width = KFullSmallWidth;            aConfig->height = KFullSmallHeight;        } else {            aConfig->width = KNormalSmallWidth;            aConfig->height = KNormalSmallHeight;        }    }}// Called by the view when the selection key (middle of navigator) is pressed// on a 9300/9500. We use it to mark/copy in selection modeTBool CPuttyAppUi::OfferSelectKeyL() {    if ( !iSelectMode ) {        return EFalse;    }    if ( iHaveMark ) {        HandleCommandL(ECmdCopy);    } else {        HandleCommandL(ECmdMark);    }    return ETrue;}// MDialObserver::DialCompleted()void CPuttyAppUi::DialCompleted(TInt aError) {    assert(iState == EStateDialing);    CEikonEnv *eenv = CEikonEnv::Static();        eenv->BusyMsgCancel();        if ( aError != KErrNone ) {        HBufC *msg = HBufC::NewLC(512);        TPtr msgp = msg->Des();        HBufC *err = HBufC::NewLC(128);        TPtr errp = err->Des();                eenv->GetErrorText(errp, aError);        msgp.Format(*eenv->AllocReadResourceLC(R_STR_DIALUP_FAILED),                    &errp);        HBufC *title = eenv->AllocReadResourceLC(R_STR_CONNECTION_ERROR_TITLE);                CCknInfoDialog::RunDlgLD(*title, msgp);        CleanupStack::PopAndDestroy(4); // title, formatstring, err, msg        iState = EStateNone;        return;    }    TRAPD(error, eenv->BusyMsgL(R_STR_CONNECTING));    if ( error != KErrNone ) {        User::Panic(*iFatalErrorPanic, error);    }    iState = EStateConnecting;    TInt err = iEngine->Connect();    if ( err != KErrNone ) {        TBuf<128> msg;        iEngine->GetErrorMessage(msg);        ConnectionErrorL(msg);        // FIXME: We should be in a state where we can exit more cleanly        User::Exit(KExitReason);    }    iState = EStateConnected;    eenv->BusyMsgCancel();    iAppView->Terminal()->SetGrayed(EFalse);    CEikButtonGroupContainer *cba =        CEikonEnv::Static()->AppUiFactory()->ToolBar();    cba->SetCommandL(KSelectButtonPos, R_PUTTY_SELECT_CBA);    cba->DrawDeferred();}// MRecordObserver::RecordCompleted()void CPuttyAppUi::RecordCompleted(TInt aError) {    CEikonEnv *eenv = CEikonEnv::Static();    eenv->BusyMsgCancel();    // If the audio device was reserved, prompt to try again    if ( aError == KErrInUse ) {        if ( CCknConfirmationDialog::RunDlgLD(R_STR_RECORD_ERROR_TITLE,                                              R_STR_AUDIO_DEVICE_IN_USE,                                              NULL,                                              R_STR_OK_CONFIRM) ) {            iRecorder->CancelRecord();            iAudioRecordDes.SetLength(0);            iRecorder->RecordL(iAudioRecordDes);            iRecording = ETrue;            CEikonEnv::Static()->BusyMsgL(R_STR_RECORDING);            return;        }            } else if ( aError != KErrNone ) {                // Handle other errors                            iRecorder->CancelRecord();                HBufC *title =            CEikonEnv::Static()->AllocReadResourceLC(R_STR_RECORD_ERROR_TITLE);        HBufC *msg = HBufC::NewLC(512);        TPtr msgp = msg->Des();        HBufC *err = HBufC::NewLC(128);        TPtr errp = err->Des();                eenv->GetErrorText(errp, aError);        msgp.Format(*eenv->AllocReadResourceLC(R_STR_RECORD_FAILED),                    &errp);                CCknInfoDialog::RunDlgLD(*title, msgp);        CleanupStack::PopAndDestroy(4); // formatstring, err, msg, title    } else {        // Use the data as random number seed noise.        iEngine->AddRandomNoise(iAudioRecordDes);        eenv->InfoMsg(R_STR_RANDOMIZED);    }    delete iAudio;    iAudio = NULL;    iRecording = EFalse;        }// MPuttyClient::DrawText()void CPuttyAppUi::DrawText(TInt aX, TInt aY, const TDesC &aText,                           TBool aBold, TBool aUnderline,                           TRgb aForeground, TRgb aBackground) {        iAppView->Terminal()->DrawText(aX, aY, aText, aBold, aUnderline,                                   aForeground, aBackground);}// MPuttyClient::SetCursor()void CPuttyAppUi::SetCursor(TInt aX, TInt aY) {        iAppView->Terminal()->SetCursor(aX, aY);}// MPuttyClient::ConnectionError()void CPuttyAppUi::ConnectionError(const TDesC &aMessage) {    TRAPD(error, ConnectionErrorL(aMessage));    if ( error != KErrNone ) {        User::Panic(*iFatalErrorPanic, error);    }    iAppView->Terminal()->SetGrayed(ETrue);}void CPuttyAppUi::ConnectionErrorL(const TDesC &aMessage) {    HBufC *title =        CEikonEnv::Static()->AllocReadResourceLC(R_STR_CONNECTION_ERROR_TITLE);    CCknInfoDialog::RunDlgLD(*title, aMessage);    CleanupStack::PopAndDestroy();    User::Exit(KExitReason);}// MPuttyClient::FatalError()void CPuttyAppUi::FatalError(const TDesC &aMessage) {    TRAPD(error, FatalErrorL(aMessage));    if ( error != KErrNone ) {        User::Panic(*iFatalErrorPanic, error);    }}void CPuttyAppUi::FatalErrorL(const TDesC &aMessage) {    HBufC *title =        CEikonEnv::Static()->AllocReadResourceLC(R_STR_FATAL_ERROR_TITLE);    CCknInfoDialog::RunDlgLD(*title, aMessage);    CleanupStack::PopAndDestroy();    User::Exit(KExitReason);}// MPuttyClient::ConnectionClosed()void CPuttyAppUi::ConnectionClosed() {    CEikonEnv::Static()->InfoMsg(R_STR_CONNECTION_CLOSED);    iAppView->Terminal()->SetGrayed(ETrue);    iState = EStateDisconnected;}// MPuttyClient::UnknownHostKey()//THostKeyResponse CPuttyAppUi::UnknownHostKey(const TDesC &aFingerprint) {MPuttyClient::THostKeyResponse CPuttyAppUi::UnknownHostKey(    const TDesC &aFingerprint) {        MPuttyClient::THostKeyResponse resp = EAbadonConnection;    TRAPD(error, resp = HostKeyDialogL(aFingerprint,                                       R_STR_UNKNOWN_HOST_KEY_TITLE,                                       R_STR_UNKNOWN_HOST_KEY_DLG_FMT));    if ( error != KErrNone ) {        User::Panic(*iFatalErrorPanic, error);    }    return resp;}// MPuttyClient::DifferentHostKey()MPuttyClient::THostKeyResponse CPuttyAppUi::DifferentHostKey(    const TDesC &aFingerprint) {        MPuttyClient::THostKeyResponse resp = EAbadonConnection;    TRAPD(error, resp = HostKeyDialogL(aFingerprint,                                       R_STR_DIFFERENT_HOST_KEY_TITLE,                                       R_STR_DIFFERENT_HOST_KEY_DLG_FMT));    if ( error != KErrNone ) {        User::Panic(*iFatalErrorPanic, error);    }    return resp;}MPuttyClient::THostKeyResponse CPuttyAppUi::HostKeyDialogL(    const TDesC &aFingerprint, TInt aDialogTitleRes, TInt aDialogFormatRes) {    CEikonEnv *env = CEikonEnv::Static();    HBufC *title = env->AllocReadResourceLC(aDialogTitleRes);    HBufC *fmt = env->AllocReadResourceLC(aDialogFormatRes);    HBufC *contents = HBufC::NewLC(fmt->Length() + aFingerprint.Length());    contents->Des().Format(*fmt, &aFingerprint);    TInt res = CCknConfirmationDialog::RunDlgLD(        *title, *contents, R_UNKNOWN_HOST_KEY_DLG_BUTTONS);    MPuttyClient::THostKeyResponse resp = EAbadonConnection;    switch ( res ) {        case ECmdHostKeyAcceptAndSave:            resp = EAcceptAndStore;            break;                case ECmdHostKeyAcceptOnce:            resp = EAcceptTemporarily;            break;        case ECmdHostKeyReject:            resp = EAbadonConnection;            break;        default:            assert(EFalse);    }    CleanupStack::PopAndDestroy(3); // contents, fmt, title    return resp;}// MPuttyClient::AcceptCipher()TBool CPuttyAppUi::AcceptCipher(const TDesC &aCipherName,                                TCipherDirection aDirection) {    TBool resp = EFalse;    TRAPD(error, resp = AcceptCipherL(aCipherName,                                      aDirection));    if ( error != KErrNone ) {        User::Panic(*iFatalErrorPanic, error);    }    return resp;}TBool CPuttyAppUi::AcceptCipherL(const TDesC &aCipherName,                                 TCipherDirection aDirection) {        CEikonEnv *env = CEikonEnv::Static();    HBufC *title = env->AllocReadResourceLC(R_STR_ACCEPT_CIPHER_TITLE);    HBufC *fmt = env->AllocReadResourceLC(R_STR_ACCEPT_CIPHER_DLG_FMT);    HBufC *dir = NULL;    switch ( aDirection ) {        case EBothDirections:            dir = env->AllocReadResourceLC(R_STR_ACCEPT_CIPHER_DIR_BOTH);            break;        case EClientToServer:            dir = env->AllocReadResourceLC(                R_STR_ACCEPT_CIPHER_CLIENT_TO_SERVER);            break;        case EServerToClient:            dir = env->AllocReadResourceLC(                R_STR_ACCEPT_CIPHER_SERVER_TO_CLIENT);            break;        default:            assert(EFalse);    }    HBufC *contents = HBufC::NewLC(fmt->Length() + aCipherName.Length() +                                   dir->Length());    contents->Des().Format(*fmt, &aCipherName, dir);    TBool res = CCknConfirmationDialog::RunDlgLD(*title, *contents);    CleanupStack::PopAndDestroy(4); // contents, fir, fmt, title    return res;}// MPuttyClient::AuthenticationPromptTBool CPuttyAppUi::AuthenticationPrompt(const TDesC &aPrompt, TDes &aTarget,                                        TBool aSecret) {    TBool res = EFalse;    TRAPD(err,          res = CAuthenticationDialog::DoPromptL(aPrompt, aTarget, aSecret));    if ( err != KErrNone ) {        User::Panic(*iFatalErrorPanic, err);    }    return res;}// MTerminalObserver::TerminalSizeChanged()void CPuttyAppUi::TerminalSizeChanged(TInt aWidth, TInt aHeight) {    assert((aWidth > 1) && (aHeight > 1));    iTermWidth = aWidth;    iTermHeight = aHeight;    if ( iEngine ) {        iEngine->SetTerminalSize(aWidth, aHeight);    }}// MTerminalObserver::KeyPressed()void CPuttyAppUi::KeyPressed(TKeyCode aCode, TUint aModifiers) {    if ( iEngine ) {        iEngine->SendKeypress(aCode, aModifiers);    }}

⌨️ 快捷键说明

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