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

📄 puttyappui.cpp

📁 大名鼎鼎的远程登录软件putty的Symbian版源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// Called by CDialer when connection status changesvoid CPuttyAppUi::DialCompletedL(TInt aError) {    assert(iState == EPuttyUIStateDialing);    iState = EPuttyUIStateConnecting;        CEikonEnv *eenv = CEikonEnv::Static();        RemoveDialWaitDialogL();        if ( aError != KErrNone ) {        HBufC *msg = HBufC::NewLC(256);        TPtr msgp = msg->Des();        HBufC *err = HBufC::NewLC(128);        TPtr errp = err->Des();                    eenv->GetErrorText(errp, aError);        msgp.Format(*eenv->AllocReadResourceLC(R_STR_CONNECTION_FAILED),                    &errp, aError);                    CAknNoteDialog* dlg = new( ELeave ) CAknNoteDialog();        dlg->SetTextL(msgp);        dlg->ExecuteDlgLD(R_INFO_MESSAGE);        CleanupStack::PopAndDestroy(3); // formatstring, err, msg                    iState = EPuttyUIStateNone;        return;    }    // Show a "Connecting to host" note before proceeding. This slows the connection    // process slightly, but the dialog has to be a modal one to make it    // visible at all, otherwise it wouldn't get shown before the PuTTY    // engine connection process starts. Since the engine connection is    // synchronous and can take quite a while, it's useful to give feedback    // to the user at this point.    CAknInformationNote *note = new (ELeave) CAknInformationNote(ETrue);    note->SetTone(CAknInformationNote::ENoTone);    note->SetTimeout(CAknInformationNote::EShortTimeout);    note->ExecuteLD(*iConnectedMsg);        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 = EPuttyUIStateConnected;    assert(iTerminal);    iTerminalView->SetTerminalGrayed(EFalse);}#ifndef PUTTY_NO_AUDIORECORDER// MRecordObserver::RecordCompleted()void CPuttyAppUi::RecordCompleted(TInt aError) {    RemoveRecordWaitDialogL();        CEikonEnv *eenv = CEikonEnv::Static();    // If the audio device was reserved, prompt to try again    if ( aError == KErrInUse ) {        if ( CAknQueryDialog::NewL()->ExecuteLD(R_RECORDER_IN_USE) ) {            iRecorder->CancelRecord();            iAudioRecordDes.SetLength(0);            iRecorder->RecordL(iAudioRecordDes);            iRecording = ETrue;            return;        }            } else if ( aError != KErrNone ) {        // Handle other errors                            iRecorder->CancelRecord();                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);                CAknNoteDialog* dlg = new( ELeave ) CAknNoteDialog();        dlg->SetTextL( msgp );        dlg->ExecuteDlgLD(R_INFO_MESSAGE);        CleanupStack::PopAndDestroy(3); // formatstring, err, msg    } else {        // Use the data as random number seed noise.        iEngine->AddRandomNoise(iAudioRecordDes);        ShowInformationNoteL(R_STR_RANDOMIZED);    }    delete iAudio;    iAudio = NULL;    iRecording = EFalse;        }#endif// MPuttyClient::DrawText()void CPuttyAppUi::DrawText(TInt aX, TInt aY, const TDesC &aText, TBool aBold,                           TBool aUnderline, TRgb aForeground,                           TRgb aBackground) {    if ( iTerminal ) {        iTerminal->DrawText(aX, aY, aText, aBold, aUnderline, aForeground,                            aBackground);    }}// MPuttyClient::SetCursor()void CPuttyAppUi::SetCursor(TInt aX, TInt aY) {    if ( iTerminal ) {        iTerminal->SetCursor(aX, aY);    }}// MPuttyClient::ConnectionError()void CPuttyAppUi::ConnectionError(const TDesC &aMessage) {    TRAPD(error, ConnectionErrorL(aMessage));    if ( error != KErrNone ) {        User::Panic(*iFatalErrorPanic, error);    }    if ( iTerminal ) {        iTerminalView->SetTerminalGrayed(ETrue);    }}void CPuttyAppUi::ConnectionErrorL(const TDesC &aMessage) {    CAknNoteDialog* dlg = new( ELeave ) CAknNoteDialog();    dlg->SetTextL( aMessage );    dlg->ExecuteDlgLD(R_INFO_MESSAGE);    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) {    CAknNoteDialog* dlg = new( ELeave ) CAknNoteDialog();    dlg->SetTextL( aMessage );    dlg->ExecuteDlgLD(R_INFO_MESSAGE);    User::Exit(KExitReason);}// MPuttyClient::ConnectionClosed()void CPuttyAppUi::ConnectionClosed() {    ShowInformationNoteL(R_STR_CONNECTION_CLOSED);    if ( iTerminal ) {        iTerminalView->SetTerminalGrayed(ETrue);    }    iState = EPuttyUIStateDisconnected;}// MPuttyClient::UnknownHostKey()MPuttyClient::THostKeyResponse CPuttyAppUi::UnknownHostKey(    const TDesC &aFingerprint) {        MPuttyClient::THostKeyResponse resp = EAbadonConnection;    TRAPD(error, resp = HostKeyDialogL(aFingerprint,                                       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_DLG_FMT));    if ( error != KErrNone ) {        User::Panic(*iFatalErrorPanic, error);    }    return resp;}MPuttyClient::THostKeyResponse CPuttyAppUi::HostKeyDialogL(    const TDesC &aFingerprint, TInt aDialogFormatRes) {    CEikonEnv *env = CEikonEnv::Static();    HBufC *fmt = env->AllocReadResourceLC(aDialogFormatRes);    HBufC *contents = HBufC::NewLC(fmt->Length() + aFingerprint.Length());    contents->Des().Format(*fmt, &aFingerprint);    MPuttyClient::THostKeyResponse resp = EAbadonConnection;    CAknQueryDialog *dlg = CAknQueryDialog::NewL();    dlg->SetPromptL(*contents);    if ( dlg->ExecuteLD(R_HOSTKEY_QUERY) ) {        resp = EAcceptAndStore;    } else {        resp = EAbadonConnection;    }        CleanupStack::PopAndDestroy(2); // contents, fmt    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 *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 = CAknQueryDialog::NewL()->ExecuteLD(R_ACCEPT_WEAK_CIPHER);    CleanupStack::PopAndDestroy(3); // contents, dir, fmt    return res;}TBool CPuttyAppUi::AuthenticationPrompt(const TDesC &aPrompt, TDes &aTarget,                                        TBool aSecret) {    TBool ret = EFalse;    TRAPD(error, ret = AuthenticationPromptL(aPrompt, aTarget, aSecret));    if ( error != KErrNone ) {        User::Panic(*iFatalErrorPanic, error);    }    return ret;}    TBool CPuttyAppUi::AuthenticationPromptL(const TDesC &aPrompt, TDes &aTarget,                                        TBool aSecret) {    assert(iState == EPuttyUIStateConnected);    CAknTextQueryDialog *dlg = CAknTextQueryDialog::NewL(aTarget);        CleanupStack::PushL(dlg);    dlg->SetPromptL(aPrompt);    CleanupStack::Pop();        if ( aSecret ) {        return dlg->ExecuteLD(R_AUTH_DLG_SECRET);    }    return dlg->ExecuteLD(R_AUTH_DLG_NOT_SECRET);}// 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);    }}// MTerminalObserver::RePaintWindow()void CPuttyAppUi::RePaintWindow() {    if ( iEngine ) {        iEngine->RePaintWindow();    }}// MProgressDialogCallback::DialogDismissedL()void CPuttyAppUi::DialogDismissedL(TInt /*aButtonId*/) {    iDialWaitDialogOpen = EFalse;    if ( iState == EPuttyUIStateDialing ) {        iDialer->CancelDialL();        iState = EPuttyUIStateNone;    }}// Converts a descriptor to a null-terminated C string.void CPuttyAppUi::DesToString(const TDesC &aDes, char *aTarget,                              int targetLen) {    int i = 0;    int len = aDes.Length();    assert(len < (targetLen-1));    while ( i < len ) {        TChar c = aDes[i];        if ( c > 0x7f ) {            c = '?';        }        *aTarget++ = (char) c;        i++;    }    *aTarget = 0;}// Converts a null-terminated string to a descriptor. Doesn't support anything// except 7-bit ASCII.void CPuttyAppUi::StringToDes(const char *aStr, TDes &aTarget) {    aTarget.SetLength(0);    while ( *aStr ) {        TChar c = *aStr++;        if ( c > 0x7f ) {            c = '?';        }        aTarget.Append(c);    }}// Shows the connection establishment wait dialogvoid CPuttyAppUi::ShowDialWaitDialogL() {    // Note! This backwards way of using and dismissing the wait dialog is    // apparently due to a bug in some 7650 system software versions.    // From the S60 SDK Note control example, aknexnotecontrol.cpp:        // 1st parameter is used by only ASSERT in Sw 4.0.16.        // If NULL is passed as the perameter, crash does not occur.       CAknWaitDialog *dlg = new (ELeave) CAknWaitDialog(NULL, ETrue);    dlg->SetCallback(this);    dlg->ExecuteLD(R_DIALER_WAIT_DIALOG);    iDialWaitDialogOpen = ETrue;}// Dismisses the connection establishment wait dialogvoid CPuttyAppUi::RemoveDialWaitDialogL() {    // Check that the dialog is still open    if ( (!iDialWaitDialogOpen) || (!IsDisplayingMenuOrDialog()) ) {        iDialWaitDialogOpen = EFalse;        return;    }    // Send a simulated escape, hopefully it gets to the dialog...    TKeyEvent key;    key.iCode = EKeyEscape;    key.iModifiers = 0;    CEikonEnv::Static()->SimulateKeyEventL(key, EEventKey);    iDialWaitDialogOpen = EFalse;}// Shows the recording wait dialogvoid CPuttyAppUi::ShowRecordWaitDialogL() {    // See comments in ShowDialWaitDialogL() and RemoveDialWaitDialogL()...    CAknWaitDialog *dlg = new (ELeave) CAknWaitDialog(NULL, ETrue);    dlg->SetCallback(this);    dlg->ExecuteLD(R_RECORDING_WAIT_DIALOG);}// Dismisses the recording wait dialogvoid CPuttyAppUi::RemoveRecordWaitDialogL() {    if ( IsDisplayingMenuOrDialog() ) {        TKeyEvent key;        key.iCode = EKeyEscape;        key.iModifiers = 0;        CEikonEnv::Static()->SimulateKeyEventL(key, EEventKey);    }}

⌨️ 快捷键说明

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