diff --git a/src/SessionController.cpp b/src/SessionController.cpp --- a/src/SessionController.cpp +++ b/src/SessionController.cpp @@ -1578,7 +1578,7 @@ bool SessionController::isReadOnly() const { - if (!_session.isNull()) { + if (_session != nullptr) { return _session->isReadOnly(); } else { return false; diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -3421,12 +3421,6 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event) { - - if (_readOnly) { - event->accept(); - return; - } - if ((_urlHintsModifiers != 0u) && event->modifiers() == _urlHintsModifiers) { int hintSelected = event->key() - 0x31; if (hintSelected >= 0 && hintSelected < 10 && hintSelected < _filterChain->hotSpots().count()) { @@ -3445,23 +3439,27 @@ _screenWindow->screen()->setCurrentTerminalDisplay(this); - _actSel = 0; // Key stroke implies a screen update, so TerminalDisplay won't - // know where the current selection is. - - if (_allowBlinkingCursor) { - _blinkCursorTimer->start(); - if (_cursorBlinking) { - // if cursor is blinking(hidden), blink it again to show it - blinkCursorEvent(); + if (!_readOnly) { + _actSel = 0; // Key stroke implies a screen update, so TerminalDisplay won't + // know where the current selection is. + + if (_allowBlinkingCursor) { + _blinkCursorTimer->start(); + if (_cursorBlinking) { + // if cursor is blinking(hidden), blink it again to show it + blinkCursorEvent(); + } + Q_ASSERT(!_cursorBlinking); } - Q_ASSERT(!_cursorBlinking); } emit keyPressedSignal(event); #ifndef QT_NO_ACCESSIBILITY - QAccessibleTextCursorEvent textCursorEvent(this, _usedColumns * screenWindow()->screen()->getCursorY() + screenWindow()->screen()->getCursorX()); - QAccessible::updateAccessibility(&textCursorEvent); + if (!_readOnly) { + QAccessibleTextCursorEvent textCursorEvent(this, _usedColumns * screenWindow()->screen()->getCursorY() + screenWindow()->screen()->getCursorX()); + QAccessible::updateAccessibility(&textCursorEvent); + } #endif event->accept(); diff --git a/src/Vt102Emulation.cpp b/src/Vt102Emulation.cpp --- a/src/Vt102Emulation.cpp +++ b/src/Vt102Emulation.cpp @@ -37,6 +37,7 @@ // Konsole #include "KeyboardTranslator.h" +#include "SessionController.h" #include "TerminalDisplay.h" using Konsole::Vt102Emulation; @@ -1042,6 +1043,12 @@ const Qt::KeyboardModifiers modifiers = event->modifiers(); KeyboardTranslator::States states = KeyboardTranslator::NoState; + TerminalDisplay * currentView = _currentScreen->currentTerminalDisplay(); + bool isReadOnly = false; + if (currentView->sessionController() != nullptr) { + isReadOnly = currentView->sessionController()->isReadOnly(); + } + // get current states if (getMode(MODE_NewLine)) { states |= KeyboardTranslator::NewLineState; @@ -1059,16 +1066,18 @@ states |= KeyboardTranslator::ApplicationKeypadState; } - // check flow control state - if ((modifiers &Qt::ControlModifier) != 0u) { - switch (event->key()) { - case Qt::Key_S: - emit flowControlKeyPressed(true); - break; - case Qt::Key_Q: - case Qt::Key_C: // cancel flow control - emit flowControlKeyPressed(false); - break; + if (!isReadOnly) { + // check flow control state + if ((modifiers &Qt::ControlModifier) != 0u) { + switch (event->key()) { + case Qt::Key_S: + emit flowControlKeyPressed(true); + break; + case Qt::Key_Q: + case Qt::Key_C: // cancel flow control + emit flowControlKeyPressed(false); + break; + } } } @@ -1104,8 +1113,6 @@ if ( entry.command() != KeyboardTranslator::NoCommand ) { - TerminalDisplay * currentView = _currentScreen->currentTerminalDisplay(); - if ((entry.command() & KeyboardTranslator::EraseCommand) != 0) { textToSend += eraseChar(); } else if ((entry.command() & KeyboardTranslator::ScrollPageUpCommand) != 0) { @@ -1128,16 +1135,20 @@ textToSend += _codec->fromUnicode(event->text()); } - emit sendData(textToSend); + if (!isReadOnly) { + emit sendData(textToSend); + } } else { - // print an error message to the terminal if no key translator has been - // set - QString translatorError = i18n("No keyboard translator available. " - "The information needed to convert key presses " - "into characters to send to the terminal " - "is missing."); - reset(); - receiveData(translatorError.toLatin1().constData(), translatorError.count()); + if (!isReadOnly) { + // print an error message to the terminal if no key translator has been + // set + QString translatorError = i18n("No keyboard translator available. " + "The information needed to convert key presses " + "into characters to send to the terminal " + "is missing."); + reset(); + receiveData(translatorError.toLatin1().constData(), translatorError.count()); + } } }