From 9eddcdb204251dfa04762c71c3756412becf8cf3 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Tue, 24 Nov 2020 16:13:47 +0200 Subject: [PATCH] SessionController: use session() and view() member functions They make reading the code easier than _sessionDisplayConnection->view()/session(). GIT_SILENT --- src/session/SessionController.cpp | 364 +++++++++++++++--------------- src/session/SessionController.h | 4 +- 2 files changed, 183 insertions(+), 185 deletions(-) diff --git a/src/session/SessionController.cpp b/src/session/SessionController.cpp index 8af23fd9..2c6b976b 100644 --- a/src/session/SessionController.cpp +++ b/src/session/SessionController.cpp @@ -97,7 +97,7 @@ using namespace Konsole; QSet SessionController::_allControllers; int SessionController::_lastControllerId; -SessionController::SessionController(Session* session, TerminalDisplay* view, QObject* parent) +SessionController::SessionController(Session* sessionParam, TerminalDisplay* viewParam, QObject* parent) : ViewProperties(parent) , KXMLGUIClient() , _copyToGroup(nullptr) @@ -125,14 +125,14 @@ SessionController::SessionController(Session* session, TerminalDisplay* view, QO , _bookmarkValidProgramsToClear(QStringList()) , _isSearchBarEnabled(false) , _editProfileDialog(nullptr) - , _searchBar(view->searchBar()) + , _searchBar(viewParam->searchBar()) , _monitorProcessFinish(false) , _escapedUrlFilter(nullptr) { - Q_ASSERT(session); - Q_ASSERT(view); + Q_ASSERT(sessionParam); + Q_ASSERT(viewParam); - _sessionDisplayConnection = new SessionDisplayConnection(session, view, this); + _sessionDisplayConnection = new SessionDisplayConnection(sessionParam, viewParam, this); // handle user interface related to session (menus etc.) if (isKonsolePart()) { @@ -145,9 +145,9 @@ SessionController::SessionController(Session* session, TerminalDisplay* view, QO setupExtraActions(); } - connect(this, &SessionController::requestPrint, _sessionDisplayConnection->view(), &TerminalDisplay::printScreen); + connect(this, &SessionController::requestPrint, view(), &TerminalDisplay::printScreen); - actionCollection()->addAssociatedWidget(view); + actionCollection()->addAssociatedWidget(viewParam); const QList actionsList = actionCollection()->actions(); for (QAction *action : actionsList) { @@ -157,79 +157,79 @@ SessionController::SessionController(Session* session, TerminalDisplay* view, QO setIdentifier(++_lastControllerId); sessionAttributeChanged(); - connect(_sessionDisplayConnection->view(), &TerminalDisplay::compositeFocusChanged, this, &SessionController::viewFocusChangeHandler); - _sessionDisplayConnection->view()->setSessionController(this); + connect(view(), &TerminalDisplay::compositeFocusChanged, this, &SessionController::viewFocusChangeHandler); + view()->setSessionController(this); // install filter on the view to highlight URLs and files - updateFilterList(SessionManager::instance()->sessionProfile(_sessionDisplayConnection->session())); + updateFilterList(SessionManager::instance()->sessionProfile(session())); // listen for changes in session, we might need to change the enabled filters connect(ProfileManager::instance(), &Konsole::ProfileManager::profileChanged, this, &Konsole::SessionController::updateFilterList); // listen for session resize requests - connect(_sessionDisplayConnection->session(), &Konsole::Session::resizeRequest, this, &Konsole::SessionController::sessionResizeRequest); + connect(session(), &Konsole::Session::resizeRequest, this, &Konsole::SessionController::sessionResizeRequest); // listen for popup menu requests - connect(_sessionDisplayConnection->view(), &Konsole::TerminalDisplay::configureRequest, this, &Konsole::SessionController::showDisplayContextMenu); + connect(view(), &Konsole::TerminalDisplay::configureRequest, this, &Konsole::SessionController::showDisplayContextMenu); // move view to newest output when keystrokes occur - connect(_sessionDisplayConnection->view(), &Konsole::TerminalDisplay::keyPressedSignal, this, &Konsole::SessionController::trackOutput); + connect(view(), &Konsole::TerminalDisplay::keyPressedSignal, this, &Konsole::SessionController::trackOutput); // listen to activity / silence notifications from session - connect(_sessionDisplayConnection->session(), &Konsole::Session::notificationsChanged, this, &Konsole::SessionController::sessionNotificationsChanged); + connect(session(), &Konsole::Session::notificationsChanged, this, &Konsole::SessionController::sessionNotificationsChanged); // listen to title and icon changes - connect(_sessionDisplayConnection->session(), &Konsole::Session::sessionAttributeChanged, this, &Konsole::SessionController::sessionAttributeChanged); - connect(_sessionDisplayConnection->session(), &Konsole::Session::readOnlyChanged, this, &Konsole::SessionController::sessionReadOnlyChanged); + connect(session(), &Konsole::Session::sessionAttributeChanged, this, &Konsole::SessionController::sessionAttributeChanged); + connect(session(), &Konsole::Session::readOnlyChanged, this, &Konsole::SessionController::sessionReadOnlyChanged); - connect(this, &Konsole::SessionController::tabRenamedByUser, _sessionDisplayConnection->session(), &Konsole::Session::tabTitleSetByUser); - connect(this, &Konsole::SessionController::tabColoredByUser, _sessionDisplayConnection->session(), &Konsole::Session::tabColorSetByUser); + connect(this, &Konsole::SessionController::tabRenamedByUser, session(), &Konsole::Session::tabTitleSetByUser); + connect(this, &Konsole::SessionController::tabColoredByUser, session(), &Konsole::Session::tabColorSetByUser); - connect(_sessionDisplayConnection->session() , &Konsole::Session::currentDirectoryChanged , this , &Konsole::SessionController::currentDirectoryChanged); + connect(session() , &Konsole::Session::currentDirectoryChanged , this , &Konsole::SessionController::currentDirectoryChanged); // listen for color changes - connect(_sessionDisplayConnection->session(), &Konsole::Session::changeBackgroundColorRequest, _sessionDisplayConnection->view()->terminalColor(), &Konsole::TerminalColor::setBackgroundColor); - connect(_sessionDisplayConnection->session(), &Konsole::Session::changeForegroundColorRequest, _sessionDisplayConnection->view()->terminalColor(), &Konsole::TerminalColor::setForegroundColor); + connect(session(), &Konsole::Session::changeBackgroundColorRequest, view(), &Konsole::TerminalDisplay::setBackgroundColor); + connect(session(), &Konsole::Session::changeForegroundColorRequest, view(), &Konsole::TerminalDisplay::setForegroundColor); // update the title when the session starts - connect(_sessionDisplayConnection->session(), &Konsole::Session::started, this, &Konsole::SessionController::snapshot); + connect(session(), &Konsole::Session::started, this, &Konsole::SessionController::snapshot); // listen for output changes to set activity flag - connect(_sessionDisplayConnection->session()->emulation(), &Konsole::Emulation::outputChanged, this, &Konsole::SessionController::fireActivity); + connect(session()->emulation(), &Konsole::Emulation::outputChanged, this, &Konsole::SessionController::fireActivity); // listen for detection of ZModem transfer - connect(_sessionDisplayConnection->session(), &Konsole::Session::zmodemDownloadDetected, this, &Konsole::SessionController::zmodemDownload); - connect(_sessionDisplayConnection->session(), &Konsole::Session::zmodemUploadDetected, this, &Konsole::SessionController::zmodemUpload); + connect(session(), &Konsole::Session::zmodemDownloadDetected, this, &Konsole::SessionController::zmodemDownload); + connect(session(), &Konsole::Session::zmodemUploadDetected, this, &Konsole::SessionController::zmodemUpload); // listen for flow control status changes - connect(_sessionDisplayConnection->session(), &Konsole::Session::flowControlEnabledChanged, _sessionDisplayConnection->view(), &Konsole::TerminalDisplay::setFlowControlWarningEnabled); - _sessionDisplayConnection->view()->setFlowControlWarningEnabled(_sessionDisplayConnection->session()->flowControlEnabled()); + connect(session(), &Konsole::Session::flowControlEnabledChanged, view(), &Konsole::TerminalDisplay::setFlowControlWarningEnabled); + view()->setFlowControlWarningEnabled(session()->flowControlEnabled()); // take a snapshot of the session state every so often when // user activity occurs // // the timer is owned by the session so that it will be destroyed along // with the session - _interactionTimer = new QTimer(_sessionDisplayConnection->session()); + _interactionTimer = new QTimer(session()); _interactionTimer->setSingleShot(true); _interactionTimer->setInterval(500); connect(_interactionTimer, &QTimer::timeout, this, &Konsole::SessionController::snapshot); - connect(_sessionDisplayConnection->view(), &Konsole::TerminalDisplay::compositeFocusChanged, + connect(view(), &Konsole::TerminalDisplay::compositeFocusChanged, this, [this](bool focused) { if (focused) { interactionHandler(); }}); - connect(_sessionDisplayConnection->view(), &Konsole::TerminalDisplay::keyPressedSignal, + connect(view(), &Konsole::TerminalDisplay::keyPressedSignal, this, &Konsole::SessionController::interactionHandler); // take a snapshot of the session state periodically in the background - auto backgroundTimer = new QTimer(_sessionDisplayConnection->session()); + auto backgroundTimer = new QTimer(session()); backgroundTimer->setSingleShot(false); backgroundTimer->setInterval(2000); connect(backgroundTimer, &QTimer::timeout, this, &Konsole::SessionController::snapshot); backgroundTimer->start(); // xterm '10;?' request - connect(_sessionDisplayConnection->session(), &Konsole::Session::getForegroundColor, + connect(session(), &Konsole::Session::getForegroundColor, this, &Konsole::SessionController::sendForegroundColor); // xterm '11;?' request - connect(_sessionDisplayConnection->session(), &Konsole::Session::getBackgroundColor, + connect(session(), &Konsole::Session::getBackgroundColor, this, &Konsole::SessionController::sendBackgroundColor); _allControllers.insert(this); @@ -261,7 +261,7 @@ SessionController::~SessionController() } void SessionController::trackOutput(QKeyEvent* event) { - Q_ASSERT(_sessionDisplayConnection->view()->screenWindow()); + Q_ASSERT(view()->screenWindow()); // Qt has broken something, so we can't rely on just checking if certain // keys are passed as modifiers anymore. @@ -287,7 +287,7 @@ void SessionController::trackOutput(QKeyEvent* event) return; } - _sessionDisplayConnection->view()->screenWindow()->setTrackOutput(true); + view()->screenWindow()->setTrackOutput(true); } void SessionController::viewFocusChangeHandler(bool focused) @@ -301,9 +301,9 @@ void SessionController::viewFocusChangeHandler(bool focused) // by the focused view // first, disconnect any other views which are listening for bell signals from the session - disconnect(_sessionDisplayConnection->session(), &Konsole::Session::bellRequest, nullptr, nullptr); + disconnect(session(), &Konsole::Session::bellRequest, nullptr, nullptr); // second, connect the newly focused view to listen for the session's bell signal - connect(_sessionDisplayConnection->session(), &Konsole::Session::bellRequest, _sessionDisplayConnection->view(), &Konsole::TerminalDisplay::bell); + connect(session(), &Konsole::Session::bellRequest, view(), &Konsole::TerminalDisplay::bell); if ((_copyInputToAllTabsAction != nullptr) && _copyInputToAllTabsAction->isChecked()) { // A session with "Copy To All Tabs" has come into focus: @@ -320,9 +320,9 @@ void SessionController::interactionHandler() void SessionController::snapshot() { - Q_ASSERT(!_sessionDisplayConnection->session().isNull()); + Q_ASSERT(!session().isNull()); - QString title = _sessionDisplayConnection->session()->getDynamicTitle(); + QString title = session()->getDynamicTitle(); title = title.simplified(); // Visualize that the session is broadcasting to others @@ -332,32 +332,32 @@ void SessionController::snapshot() // use the fallback title if needed if (title.isEmpty()) { - title = _sessionDisplayConnection->session()->title(Session::NameRole); + title = session()->title(Session::NameRole); } - QColor color = _sessionDisplayConnection->session()->color(); + QColor color = session()->color(); // use the fallback color if needed if (!color.isValid()) { color = QColor(QColor::Invalid); } // apply new title - _sessionDisplayConnection->session()->setTitle(Session::DisplayedTitleRole, title); + session()->setTitle(Session::DisplayedTitleRole, title); // apply new color - _sessionDisplayConnection->session()->setColor(color); + session()->setColor(color); // check if foreground process ended and notify if this option was requested if (_monitorProcessFinish) { - bool isForegroundProcessActive = _sessionDisplayConnection->session()->isForegroundProcessActive(); + bool isForegroundProcessActive = session()->isForegroundProcessActive(); if (!_previousForegroundProcessName.isNull() && !isForegroundProcessActive) { - KNotification::event(_sessionDisplayConnection->session()->hasFocus() ? QStringLiteral("ProcessFinished") : QStringLiteral("ProcessFinishedHidden"), - i18n("The process '%1' has finished running in session '%2'", _previousForegroundProcessName, _sessionDisplayConnection->session()->nameTitle()), + KNotification::event(session()->hasFocus() ? QStringLiteral("ProcessFinished") : QStringLiteral("ProcessFinishedHidden"), + i18n("The process '%1' has finished running in session '%2'", _previousForegroundProcessName, session()->nameTitle()), QPixmap(), QApplication::activeWindow(), KNotification::CloseWhenWidgetActivated); } - _previousForegroundProcessName = isForegroundProcessActive ? _sessionDisplayConnection->session()->foregroundProcessName() : QString(); + _previousForegroundProcessName = isForegroundProcessActive ? session()->foregroundProcessName() : QString(); } // do not forget icon @@ -366,12 +366,12 @@ void SessionController::snapshot() QString SessionController::currentDir() const { - return _sessionDisplayConnection->session()->currentWorkingDirectory(); + return session()->currentWorkingDirectory(); } QUrl SessionController::url() const { - return _sessionDisplayConnection->session()->getUrl(); + return session()->getUrl(); } void SessionController::rename() @@ -382,22 +382,22 @@ void SessionController::rename() void SessionController::openUrl(const QUrl& url) { // Clear shell's command line - if (!_sessionDisplayConnection->session()->isForegroundProcessActive() - && _bookmarkValidProgramsToClear.contains(_sessionDisplayConnection->session()->foregroundProcessName())) { - _sessionDisplayConnection->session()->sendTextToTerminal(QChar(0x03), QLatin1Char('\n')); // Ctrl+C + if (!session()->isForegroundProcessActive() + && _bookmarkValidProgramsToClear.contains(session()->foregroundProcessName())) { + session()->sendTextToTerminal(QChar(0x03), QLatin1Char('\n')); // Ctrl+C } // handle local paths if (url.isLocalFile()) { QString path = url.toLocalFile(); - _sessionDisplayConnection->session()->sendTextToTerminal(QStringLiteral("cd ") + KShell::quoteArg(path), QLatin1Char('\r')); + session()->sendTextToTerminal(QStringLiteral("cd ") + KShell::quoteArg(path), QLatin1Char('\r')); } else if (url.scheme().isEmpty()) { // QUrl couldn't parse what the user entered into the URL field // so just dump it to the shell // If you change this, change it also in autotests/BookMarkTest.cpp QString command = QUrl::fromPercentEncoding(url.toEncoded()); if (!command.isEmpty()) { - _sessionDisplayConnection->session()->sendTextToTerminal(command, QLatin1Char('\r')); + session()->sendTextToTerminal(command, QLatin1Char('\r')); } } else if (url.scheme() == QLatin1String("ssh")) { QString sshCommand = QStringLiteral("ssh "); @@ -411,7 +411,7 @@ void SessionController::openUrl(const QUrl& url) if (!url.host().isEmpty()) { sshCommand += url.host(); } - _sessionDisplayConnection->session()->sendTextToTerminal(sshCommand, QLatin1Char('\r')); + session()->sendTextToTerminal(sshCommand, QLatin1Char('\r')); } else if (url.scheme() == QLatin1String("telnet")) { QString telnetCommand = QStringLiteral("telnet "); @@ -426,12 +426,12 @@ void SessionController::openUrl(const QUrl& url) telnetCommand += QString::number(url.port()); } - _sessionDisplayConnection->session()->sendTextToTerminal(telnetCommand, QLatin1Char('\r')); + session()->sendTextToTerminal(telnetCommand, QLatin1Char('\r')); } else { //TODO Implement handling for other Url types - KMessageBox::sorry(_sessionDisplayConnection->view()->window(), + KMessageBox::sorry(view()->window(), i18n("Konsole does not know how to open the bookmark: ") + url.toDisplayString()); @@ -558,19 +558,19 @@ void SessionController::configureWebShortcuts() void SessionController::sendSignal(QAction* action) { const auto signal = action->data().toInt(); - _sessionDisplayConnection->session()->sendSignal(signal); + session()->sendSignal(signal); } void SessionController::sendForegroundColor(uint terminator) { - const QColor c = _sessionDisplayConnection->view()->terminalColor()->foregroundColor(); - _sessionDisplayConnection->session()->reportForegroundColor(c, terminator); + const QColor c = view()->getForegroundColor(); + session()->reportForegroundColor(c, terminator); } void Konsole::SessionController::sendBackgroundColor(uint terminator) { - const QColor c = _sessionDisplayConnection->view()->terminalColor()->backgroundColor(); - _sessionDisplayConnection->session()->reportBackgroundColor(c, terminator); + const QColor c = view()->getBackgroundColor(); + session()->reportBackgroundColor(c, terminator); } void SessionController::toggleReadOnly() @@ -578,7 +578,7 @@ void SessionController::toggleReadOnly() auto *action = qobject_cast(sender()); if (action != nullptr) { bool readonly = !isReadOnly(); - _sessionDisplayConnection->session()->setReadOnly(readonly); + session()->setReadOnly(readonly); } } @@ -588,7 +588,7 @@ void SessionController::removeSearchFilter() return; } - _sessionDisplayConnection->view()->filterChain()->removeFilter(_searchFilter); + view()->filterChain()->removeFilter(_searchFilter); delete _searchFilter; _searchFilter = nullptr; } @@ -734,8 +734,8 @@ void SessionController::setupCommonActions() _codecAction = new KCodecAction(i18n("Set &Encoding"), this); _codecAction->setIcon(QIcon::fromTheme(QStringLiteral("character-set"))); collection->addAction(QStringLiteral("set-encoding"), _codecAction); - _codecAction->setCurrentCodec(QString::fromUtf8(_sessionDisplayConnection->session()->codec())); - connect(_sessionDisplayConnection->session(), &Konsole::Session::sessionCodecChanged, this, &Konsole::SessionController::updateCodecAction); + _codecAction->setCurrentCodec(QString::fromUtf8(session()->codec())); + connect(session(), &Konsole::Session::sessionCodecChanged, this, &Konsole::SessionController::updateCodecAction); connect(_codecAction, QOverload::of(&KCodecAction::triggered), this, &Konsole::SessionController::changeCodec); @@ -879,7 +879,7 @@ void SessionController::setupExtraActions() void SessionController::switchProfile(const Profile::Ptr &profile) { - SessionManager::instance()->setSessionProfile(_sessionDisplayConnection->session(), profile); + SessionManager::instance()->setSessionProfile(session(), profile); _switchProfileMenu->setIcon(QIcon::fromTheme(profile->icon())); updateFilterList(profile); } @@ -901,7 +901,7 @@ void SessionController::updateCodecAction(QTextCodec *codec) void SessionController::changeCodec(QTextCodec* codec) { - _sessionDisplayConnection->session()->setCodec(codec); + session()->setCodec(codec); } EditProfileDialog* SessionController::profileDialogPointer() @@ -916,7 +916,7 @@ void SessionController::editCurrentProfile() if ( (controller->profileDialogPointer() != nullptr) && controller->profileDialogPointer()->isVisible() && (controller->profileDialogPointer()->lookupProfile() - == SessionManager::instance()->sessionProfile(_sessionDisplayConnection->session())) ) { + == SessionManager::instance()->sessionProfile(session())) ) { controller->profileDialogPointer()->close(); } } @@ -928,28 +928,28 @@ void SessionController::editCurrentProfile() } _editProfileDialog = new EditProfileDialog(QApplication::activeWindow()); - _editProfileDialog->setProfile(SessionManager::instance()->sessionProfile(_sessionDisplayConnection->session())); + _editProfileDialog->setProfile(SessionManager::instance()->sessionProfile(session())); _editProfileDialog->show(); } void SessionController::renameSession() { - const QString &sessionLocalTabTitleFormat = _sessionDisplayConnection->session()->tabTitleFormat(Session::LocalTabTitle); - const QString &sessionRemoteTabTitleFormat = _sessionDisplayConnection->session()->tabTitleFormat(Session::RemoteTabTitle); - const QColor &sessionTabColor = _sessionDisplayConnection->session()->color(); + const QString &sessionLocalTabTitleFormat = session()->tabTitleFormat(Session::LocalTabTitle); + const QString &sessionRemoteTabTitleFormat = session()->tabTitleFormat(Session::RemoteTabTitle); + const QColor &sessionTabColor = session()->color(); QScopedPointer dialog(new RenameTabDialog(QApplication::activeWindow())); dialog->setTabTitleText(sessionLocalTabTitleFormat); dialog->setRemoteTabTitleText(sessionRemoteTabTitleFormat); dialog->setColor(sessionTabColor); - if (_sessionDisplayConnection->session()->isRemote()) { + if (session()->isRemote()) { dialog->focusRemoteTabTitleText(); } else { dialog->focusTabTitleText(); } - QPointer guard(_sessionDisplayConnection->session()); + QPointer guard(session()); int result = dialog->exec(); if (guard.isNull()) { return; @@ -961,20 +961,20 @@ void SessionController::renameSession() const QColor &tabColor = dialog->color(); if (tabTitle != sessionLocalTabTitleFormat) { - _sessionDisplayConnection->session()->setTabTitleFormat(Session::LocalTabTitle, tabTitle); + session()->setTabTitleFormat(Session::LocalTabTitle, tabTitle); emit tabRenamedByUser(true); // trigger an update of the tab text snapshot(); } if(remoteTabTitle != sessionRemoteTabTitleFormat) { - _sessionDisplayConnection->session()->setTabTitleFormat(Session::RemoteTabTitle, remoteTabTitle); + session()->setTabTitleFormat(Session::RemoteTabTitle, remoteTabTitle); emit tabRenamedByUser(true); snapshot(); } if (tabColor != sessionTabColor) { - _sessionDisplayConnection->session()->setColor(tabColor); + session()->setColor(tabColor); emit tabColoredByUser(true); snapshot(); } @@ -984,8 +984,8 @@ void SessionController::renameSession() // This is called upon Menu->Close Sesssion and right-click on tab->Close Tab bool SessionController::confirmClose() const { - if (_sessionDisplayConnection->session()->isForegroundProcessActive()) { - QString title = _sessionDisplayConnection->session()->foregroundProcessName(); + if (session()->isForegroundProcessActive()) { + QString title = session()->foregroundProcessName(); // hard coded for now. In future make it possible for the user to specify which programs // are ignored when considering whether to display a confirmation @@ -1004,7 +1004,7 @@ bool SessionController::confirmClose() const " Are you sure you want to close it?", title); } - int result = KMessageBox::warningYesNo(_sessionDisplayConnection->view()->window(), + int result = KMessageBox::warningYesNo(view()->window(), question, i18n("Confirm Close"), KStandardGuiItem::yes(), @@ -1016,8 +1016,8 @@ bool SessionController::confirmClose() const } bool SessionController::confirmForceClose() const { - if (_sessionDisplayConnection->session()->isRunning()) { - QString title = _sessionDisplayConnection->session()->program(); + if (session()->isRunning()) { + QString title = session()->program(); // hard coded for now. In future make it possible for the user to specify which programs // are ignored when considering whether to display a confirmation @@ -1036,7 +1036,7 @@ bool SessionController::confirmForceClose() const " Are you sure you want to kill it by force?", title); } - int result = KMessageBox::warningYesNo(_sessionDisplayConnection->view()->window(), question, i18n("Confirm Close")); + int result = KMessageBox::warningYesNo(view()->window(), question, i18n("Confirm Close")); return result == KMessageBox::Yes; } return true; @@ -1051,12 +1051,12 @@ void SessionController::closeSession() return; } - if (!_sessionDisplayConnection->session()->closeInNormalWay()) { + if (!session()->closeInNormalWay()) { if (!confirmForceClose()) { return; } - if (!_sessionDisplayConnection->session()->closeInForceWay()) { + if (!session()->closeInForceWay()) { qCDebug(KonsoleDebug) << "Konsole failed to close a session in any way."; return; } @@ -1086,24 +1086,24 @@ void SessionController::openBrowser() void SessionController::copy() { - _sessionDisplayConnection->view()->copyToClipboard(); + view()->copyToClipboard(); } void SessionController::paste() { - _sessionDisplayConnection->view()->pasteFromClipboard(); + view()->pasteFromClipboard(); } void SessionController::pasteFromX11Selection() { - _sessionDisplayConnection->view()->pasteFromX11Selection(); + view()->pasteFromX11Selection(); } void SessionController::selectAll() { - _sessionDisplayConnection->view()->selectAll(); + view()->selectAll(); } void SessionController::selectLine() { - _sessionDisplayConnection->view()->selectCurrentLine(); + view()->selectCurrentLine(); } static const KXmlGuiWindow* findWindow(const QObject* object) { @@ -1158,7 +1158,7 @@ void SessionController::copyInputToAllTabs() } // Find our window ... - const KXmlGuiWindow* myWindow = findWindow(_sessionDisplayConnection->view()); + const KXmlGuiWindow* myWindow = findWindow(view()); const QList sessionsList = SessionManager::instance()->sessions(); #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) @@ -1176,7 +1176,7 @@ void SessionController::copyInputToAllTabs() _copyToGroup->addSession(session); } } - _copyToGroup->setMasterStatus(_sessionDisplayConnection->session(), true); + _copyToGroup->setMasterStatus(session(), true); _copyToGroup->setMasterMode(SessionGroup::CopyInputToAll); snapshot(); @@ -1187,13 +1187,13 @@ void SessionController::copyInputToSelectedTabs() { if (_copyToGroup == nullptr) { _copyToGroup = new SessionGroup(this); - _copyToGroup->addSession(_sessionDisplayConnection->session()); - _copyToGroup->setMasterStatus(_sessionDisplayConnection->session(), true); + _copyToGroup->addSession(session()); + _copyToGroup->setMasterStatus(session(), true); _copyToGroup->setMasterMode(SessionGroup::CopyInputToAll); } - QPointer dialog = new CopyInputDialog(_sessionDisplayConnection->view()); - dialog->setMasterSession(_sessionDisplayConnection->session()); + QPointer dialog = new CopyInputDialog(view()); + dialog->setMasterSession(session()); const QList sessionsList = _copyToGroup->sessions(); #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) @@ -1202,11 +1202,11 @@ void SessionController::copyInputToSelectedTabs() QSet currentGroup = QSet::fromList(sessionsList); #endif - currentGroup.remove(_sessionDisplayConnection->session()); + currentGroup.remove(session()); dialog->setChosenSessions(currentGroup); - QPointer guard(_sessionDisplayConnection->session()); + QPointer guard(session()); int result = dialog->exec(); if (guard.isNull()) { return; @@ -1214,7 +1214,7 @@ void SessionController::copyInputToSelectedTabs() if (result == QDialog::Accepted) { QSet newGroup = dialog->chosenSessions(); - newGroup.remove(_sessionDisplayConnection->session()); + newGroup.remove(session()); const QSet completeGroup = newGroup | currentGroup; for (Session *session : completeGroup) { @@ -1225,7 +1225,7 @@ void SessionController::copyInputToSelectedTabs() } } - _copyToGroup->setMasterStatus(_sessionDisplayConnection->session(), true); + _copyToGroup->setMasterStatus(session(), true); _copyToGroup->setMasterMode(SessionGroup::CopyInputToAll); snapshot(); emit copyInputChanged(this); @@ -1247,9 +1247,9 @@ void SessionController::copyInputToNone() #endif for (auto iterator : group) { - Session* session = iterator; + Session *s = iterator; - if (session != _sessionDisplayConnection->session()) { + if (s != session()) { _copyToGroup->removeSession(iterator); } } @@ -1267,20 +1267,18 @@ void SessionController::searchClosed() void SessionController::updateFilterList(const Profile::Ptr &profile) { - if (profile != SessionManager::instance()->sessionProfile(_sessionDisplayConnection->session())) { + if (profile != SessionManager::instance()->sessionProfile(session())) { return; } - auto session = _sessionDisplayConnection->session(); - auto view = _sessionDisplayConnection->view(); - auto *filterChain = view->filterChain(); + auto *filterChain = view()->filterChain(); const QString currentWordCharacters = profile->wordCharacters(); static QString _wordChars = currentWordCharacters; if (profile->underlineFilesEnabled()) { if (_fileFilter == nullptr) { // Initialize - _fileFilter = new FileFilter(session, currentWordCharacters); + _fileFilter = new FileFilter(session(), currentWordCharacters); filterChain->addFilter(_fileFilter); } else { // If wordCharacters changed, we need to change the static regex @@ -1309,7 +1307,7 @@ void SessionController::updateFilterList(const Profile::Ptr &profile) if (profile->allowEscapedLinks()) { if (_escapedUrlFilter == nullptr) { // Initialize - _escapedUrlFilter = new EscapeSequenceUrlFilter(session, view); + _escapedUrlFilter = new EscapeSequenceUrlFilter(session(), view()); filterChain->addFilter(_escapedUrlFilter); } } else if (_escapedUrlFilter != nullptr) { // It became disabled, clean up @@ -1346,10 +1344,10 @@ void SessionController::listenForScreenWindowUpdates() return; } - connect(_sessionDisplayConnection->view()->screenWindow(), &Konsole::ScreenWindow::outputChanged, this, &Konsole::SessionController::updateSearchFilter); - connect(_sessionDisplayConnection->view()->screenWindow(), &Konsole::ScreenWindow::scrolled, this, &Konsole::SessionController::updateSearchFilter); - connect(_sessionDisplayConnection->view()->screenWindow(), - &Konsole::ScreenWindow::currentResultLineChanged, _sessionDisplayConnection->view(), + connect(view()->screenWindow(), &Konsole::ScreenWindow::outputChanged, this, &Konsole::SessionController::updateSearchFilter); + connect(view()->screenWindow(), &Konsole::ScreenWindow::scrolled, this, &Konsole::SessionController::updateSearchFilter); + connect(view()->screenWindow(), + &Konsole::ScreenWindow::currentResultLineChanged, view(), QOverload<>::of(&Konsole::TerminalDisplay::update)); _listenForScreenWindowUpdates = true; @@ -1358,13 +1356,13 @@ void SessionController::listenForScreenWindowUpdates() void SessionController::updateSearchFilter() { if ((_searchFilter != nullptr) && (!_searchBar.isNull())) { - _sessionDisplayConnection->view()->processFilters(); + view()->processFilters(); } } void SessionController::searchBarEvent() { - QString selectedText = _sessionDisplayConnection->view()->screenWindow()->selectedText(Screen::PreserveLineBreaks | Screen::TrimLeadingWhitespace | Screen::TrimTrailingWhitespace); + QString selectedText = view()->screenWindow()->selectedText(Screen::PreserveLineBreaks | Screen::TrimLeadingWhitespace | Screen::TrimTrailingWhitespace); if (!selectedText.isEmpty()) { _searchBar->setSearchText(selectedText); } @@ -1399,8 +1397,8 @@ void SessionController::enableSearchBar(bool showSearchBar) &Konsole::SessionController::findPreviousInHistory); disconnect(_searchBar, &Konsole::IncrementalSearchBar::searchShiftPlusReturnPressed, this, &Konsole::SessionController::findNextInHistory); - if ((!_sessionDisplayConnection->view().isNull()) && (_sessionDisplayConnection->view()->screenWindow() != nullptr)) { - _sessionDisplayConnection->view()->screenWindow()->setCurrentResultLine(-1); + if ((!view().isNull()) && (view()->screenWindow() != nullptr)) { + view()->screenWindow()->setCurrentResultLine(-1); } } } @@ -1448,8 +1446,8 @@ void SessionController::searchHistory(bool showSearchBar) _searchFilter = new RegExpFilter(); _searchFilter->setRegExp(regexpFromSearchBarOptions()); - _sessionDisplayConnection->view()->filterChain()->addFilter(_searchFilter); - _sessionDisplayConnection->view()->processFilters(); + view()->filterChain()->addFilter(_searchFilter); + view()->processFilters(); setFindNextPrevEnabled(true); } else { @@ -1457,7 +1455,7 @@ void SessionController::searchHistory(bool showSearchBar) removeSearchFilter(); - _sessionDisplayConnection->view()->setFocus(Qt::ActiveWindowFocusReason); + view()->setFocus(Qt::ActiveWindowFocusReason); } } } @@ -1469,7 +1467,7 @@ void SessionController::setFindNextPrevEnabled(bool enabled) } void SessionController::searchTextChanged(const QString& text) { - Q_ASSERT(_sessionDisplayConnection->view()->screenWindow()); + Q_ASSERT(view()->screenWindow()); if (_searchText == text) { return; @@ -1478,8 +1476,8 @@ void SessionController::searchTextChanged(const QString& text) _searchText = text; if (text.isEmpty()) { - _sessionDisplayConnection->view()->screenWindow()->clearSelection(); - _sessionDisplayConnection->view()->screenWindow()->scrollTo(_searchStartLine); + view()->screenWindow()->clearSelection(); + view()->screenWindow()->scrollTo(_searchStartLine); } // update search. this is called even when the text is @@ -1488,7 +1486,7 @@ void SessionController::searchTextChanged(const QString& text) } void SessionController::searchCompleted(bool success) { - _prevSearchResultLine = _sessionDisplayConnection->view()->screenWindow()->currentResultLine(); + _prevSearchResultLine = view()->screenWindow()->currentResultLine(); if (!_searchBar.isNull()) { _searchBar->setFoundMatch(success); @@ -1503,16 +1501,16 @@ void SessionController::beginSearch(const QString& text, Enum::SearchDirection d QRegularExpression regExp = regexpFromSearchBarOptions(); _searchFilter->setRegExp(regExp); - if (_searchStartLine < 0 || _searchStartLine > _sessionDisplayConnection->view()->screenWindow()->lineCount()) { + if (_searchStartLine < 0 || _searchStartLine > view()->screenWindow()->lineCount()) { if (direction == Enum::ForwardsSearch) { - setSearchStartTo(_sessionDisplayConnection->view()->screenWindow()->currentLine()); + setSearchStartTo(view()->screenWindow()->currentLine()); } else { - setSearchStartTo(_sessionDisplayConnection->view()->screenWindow()->currentLine() + _sessionDisplayConnection->view()->screenWindow()->windowLines()); + setSearchStartTo(view()->screenWindow()->currentLine() + view()->screenWindow()->windowLines()); } } if (!regExp.pattern().isEmpty()) { - _sessionDisplayConnection->view()->screenWindow()->setCurrentResultLine(-1); + view()->screenWindow()->setCurrentResultLine(-1); auto task = new SearchHistoryTask(this); connect(task, &Konsole::SearchHistoryTask::completed, this, &Konsole::SessionController::searchCompleted); @@ -1521,24 +1519,24 @@ void SessionController::beginSearch(const QString& text, Enum::SearchDirection d task->setSearchDirection(direction); task->setAutoDelete(true); task->setStartLine(_searchStartLine); - task->addScreenWindow(_sessionDisplayConnection->session() , _sessionDisplayConnection->view()->screenWindow()); + task->addScreenWindow(session() , view()->screenWindow()); task->execute(); } else if (text.isEmpty()) { searchCompleted(false); } - _sessionDisplayConnection->view()->processFilters(); + view()->processFilters(); } void SessionController::highlightMatches(bool highlight) { if (highlight) { - _sessionDisplayConnection->view()->filterChain()->addFilter(_searchFilter); - _sessionDisplayConnection->view()->processFilters(); + view()->filterChain()->addFilter(_searchFilter); + view()->processFilters(); } else { - _sessionDisplayConnection->view()->filterChain()->removeFilter(_searchFilter); + view()->filterChain()->removeFilter(_searchFilter); } - _sessionDisplayConnection->view()->update(); + view()->update(); } void SessionController::searchFrom() @@ -1547,7 +1545,7 @@ void SessionController::searchFrom() Q_ASSERT(_searchFilter); if (reverseSearchChecked()) { - setSearchStartTo(_sessionDisplayConnection->view()->screenWindow()->lineCount()); + setSearchStartTo(view()->screenWindow()->lineCount()); } else { setSearchStartTo(0); } @@ -1579,13 +1577,13 @@ void SessionController::changeSearchMatch() Q_ASSERT(_searchFilter); // reset Selection for new case match - _sessionDisplayConnection->view()->screenWindow()->clearSelection(); + view()->screenWindow()->clearSelection(); beginSearch(_searchBar->searchText(), reverseSearchChecked() ? Enum::BackwardsSearch : Enum::ForwardsSearch); } void SessionController::showHistoryOptions() { QScopedPointer dialog(new HistorySizeDialog(QApplication::activeWindow())); - const HistoryType& currentHistory = _sessionDisplayConnection->session()->historyType(); + const HistoryType& currentHistory = session()->historyType(); if (currentHistory.isEnabled()) { if (currentHistory.isUnlimited()) { @@ -1598,7 +1596,7 @@ void SessionController::showHistoryOptions() dialog->setMode(Enum::NoHistory); } - QPointer guard(_sessionDisplayConnection->session()); + QPointer guard(session()); int result = dialog->exec(); if (guard.isNull()) { return; @@ -1611,19 +1609,19 @@ void SessionController::showHistoryOptions() void SessionController::sessionResizeRequest(const QSize& size) { ////qDebug() << "View resize requested to " << size; - _sessionDisplayConnection->view()->setSize(size.width(), size.height()); + view()->setSize(size.width(), size.height()); } void SessionController::scrollBackOptionsChanged(int mode, int lines) { switch (mode) { case Enum::NoHistory: - _sessionDisplayConnection->session()->setHistoryType(HistoryTypeNone()); + session()->setHistoryType(HistoryTypeNone()); break; case Enum::FixedSizeHistory: - _sessionDisplayConnection->session()->setHistoryType(CompactHistoryType(lines)); + session()->setHistoryType(CompactHistoryType(lines)); break; case Enum::UnlimitedHistory: - _sessionDisplayConnection->session()->setHistoryType(HistoryTypeFile()); + session()->setHistoryType(HistoryTypeFile()); break; } } @@ -1632,51 +1630,51 @@ void SessionController::saveHistory() { SessionTask* task = new SaveHistoryTask(this); task->setAutoDelete(true); - task->addSession(_sessionDisplayConnection->session()); + task->addSession(session()); task->execute(); } void SessionController::clearHistory() { - _sessionDisplayConnection->session()->clearHistory(); - _sessionDisplayConnection->view()->updateImage(); // To reset view scrollbar - _sessionDisplayConnection->view()->repaint(); + session()->clearHistory(); + view()->updateImage(); // To reset view scrollbar + view()->repaint(); } void SessionController::clearHistoryAndReset() { - Profile::Ptr profile = SessionManager::instance()->sessionProfile(_sessionDisplayConnection->session()); + Profile::Ptr profile = SessionManager::instance()->sessionProfile(session()); QByteArray name = profile->defaultEncoding().toUtf8(); - Emulation* emulation = _sessionDisplayConnection->session()->emulation(); + Emulation* emulation = session()->emulation(); emulation->reset(); - _sessionDisplayConnection->session()->refresh(); - _sessionDisplayConnection->session()->setCodec(QTextCodec::codecForName(name)); + session()->refresh(); + session()->setCodec(QTextCodec::codecForName(name)); clearHistory(); } void SessionController::increaseFontSize() { - _sessionDisplayConnection->view()->increaseFontSize(); + view()->increaseFontSize(); } void SessionController::decreaseFontSize() { - _sessionDisplayConnection->view()->decreaseFontSize(); + view()->decreaseFontSize(); } void SessionController::resetFontSize() { - _sessionDisplayConnection->view()->resetFontSize(); + view()->resetFontSize(); } void SessionController::monitorActivity(bool monitor) { - _sessionDisplayConnection->session()->setMonitorActivity(monitor); + session()->setMonitorActivity(monitor); } void SessionController::monitorSilence(bool monitor) { - _sessionDisplayConnection->session()->setMonitorSilence(monitor); + session()->setMonitorSilence(monitor); } void SessionController::monitorProcessFinish(bool monitor) { @@ -1686,10 +1684,10 @@ void SessionController::updateSessionIcon() { // If the default profile icon is being used, don't put it on the tab // Only show the icon if the user specifically chose one - if (_sessionDisplayConnection->session()->iconName() == QStringLiteral("utilities-terminal")) { + if (session()->iconName() == QStringLiteral("utilities-terminal")) { _sessionIconName = QString(); } else { - _sessionIconName = _sessionDisplayConnection->session()->iconName(); + _sessionIconName = session()->iconName(); } _sessionIcon = QIcon::fromTheme(_sessionIconName); @@ -1725,14 +1723,14 @@ void SessionController::updateReadOnlyActionStates() // Without the timer, when detaching a tab while the message widget is visible, // the size of the terminal becomes really small... QTimer::singleShot(0, this, [this, readonly]() { - _sessionDisplayConnection->view()->updateReadOnlyState(readonly); + view()->updateReadOnlyState(readonly); }); } bool SessionController::isReadOnly() const { - if (!_sessionDisplayConnection->session().isNull()) { - return _sessionDisplayConnection->session()->isReadOnly(); + if (!session().isNull()) { + return session()->isReadOnly(); } else { return false; } @@ -1745,25 +1743,25 @@ bool SessionController::isCopyInputActive() const void SessionController::sessionAttributeChanged() { - if (_sessionIconName != _sessionDisplayConnection->session()->iconName()) { + if (_sessionIconName != session()->iconName()) { updateSessionIcon(); } - QString title = _sessionDisplayConnection->session()->title(Session::DisplayedTitleRole); + QString title = session()->title(Session::DisplayedTitleRole); // special handling for the "%w" marker which is replaced with the // window title set by the shell - title.replace(QLatin1String("%w"), _sessionDisplayConnection->session()->userTitle()); + title.replace(QLatin1String("%w"), session()->userTitle()); // special handling for the "%#" marker which is replaced with the // number of the shell - title.replace(QLatin1String("%#"), QString::number(_sessionDisplayConnection->session()->sessionId())); + title.replace(QLatin1String("%#"), QString::number(session()->sessionId())); if (title.isEmpty()) { - title = _sessionDisplayConnection->session()->title(Session::NameRole); + title = session()->title(Session::NameRole); } setTitle(title); - setColor(_sessionDisplayConnection->session()->color()); + setColor(session()->color()); emit rawTitleChanged(); } @@ -1773,7 +1771,7 @@ void SessionController::sessionReadOnlyChanged() { // Update all views const QList viewsList = session()->views(); for (TerminalDisplay *terminalDisplay : viewsList) { - if (terminalDisplay != _sessionDisplayConnection->view()) { + if (terminalDisplay != view()) { terminalDisplay->updateReadOnlyState(isReadOnly()); } emit readOnlyChanged(this); @@ -1786,13 +1784,13 @@ void SessionController::showDisplayContextMenu(const QPoint& position) // application did not merge our GUI. if (factory() == nullptr) { if (clientBuilder() == nullptr) { - setClientBuilder(new KXMLGUIBuilder(_sessionDisplayConnection->view())); + setClientBuilder(new KXMLGUIBuilder(view())); // Client builder does not get deleted automatically connect(this, &QObject::destroyed, this, [this]{ delete clientBuilder(); }); } - auto factory = new KXMLGUIFactory(clientBuilder(), _sessionDisplayConnection->view()); + auto factory = new KXMLGUIFactory(clientBuilder(), view()); factory->addClient(this); } @@ -1812,7 +1810,7 @@ void SessionController::showDisplayContextMenu(const QPoint& position) #endif // prepend content-specific actions such as "Open Link", "Copy Email Address" etc - QSharedPointer hotSpot = _sessionDisplayConnection->view()->filterActions(position); + QSharedPointer hotSpot = view()->filterActions(position); if (hotSpot != nullptr) { popup->insertActions(popup->actions().value(0, nullptr), hotSpot->actions() << contentSeparator ); popup->addAction(contentSeparator); @@ -1861,14 +1859,14 @@ void SessionController::showDisplayContextMenu(const QPoint& position) } } else { qCDebug(KonsoleDebug) << "Unable to display popup menu for session" - << _sessionDisplayConnection->session()->title(Session::NameRole) + << session()->title(Session::NameRole) << ", no GUI factory available to build the popup."; } } void SessionController::movementKeyFromSearchBarReceived(QKeyEvent *event) { - QCoreApplication::sendEvent(_sessionDisplayConnection->view(), event); + QCoreApplication::sendEvent(view(), event); setSearchStartToWindowCurrentLine(); } @@ -1884,28 +1882,28 @@ void SessionController::zmodemDownload() zmodem = QStandardPaths::findExecutable(QStringLiteral("lrz")); } if (!zmodem.isEmpty()) { - const QString path = QFileDialog::getExistingDirectory(_sessionDisplayConnection->view(), + const QString path = QFileDialog::getExistingDirectory(view(), i18n("Save ZModem Download to..."), QDir::homePath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (!path.isEmpty()) { - _sessionDisplayConnection->session()->startZModem(zmodem, path, QStringList()); + session()->startZModem(zmodem, path, QStringList()); return; } } else { - KMessageBox::error(_sessionDisplayConnection->view(), + KMessageBox::error(view(), i18n("

A ZModem file transfer attempt has been detected, " "but no suitable ZModem software was found on this system.

" "

You may wish to install the 'rzsz' or 'lrzsz' package.

")); } - _sessionDisplayConnection->session()->cancelZModem(); + session()->cancelZModem(); } void SessionController::zmodemUpload() { - if (_sessionDisplayConnection->session()->isZModemBusy()) { - KMessageBox::sorry(_sessionDisplayConnection->view(), + if (session()->isZModemBusy()) { + KMessageBox::sorry(view(), i18n("

The current session already has a ZModem file transfer in progress.

")); return; } @@ -1915,17 +1913,17 @@ void SessionController::zmodemUpload() zmodem = QStandardPaths::findExecutable(QStringLiteral("lsz")); } if (zmodem.isEmpty()) { - KMessageBox::sorry(_sessionDisplayConnection->view(), + KMessageBox::sorry(view(), i18n("

No suitable ZModem software was found on this system.

" "

You may wish to install the 'rzsz' or 'lrzsz' package.

")); return; } - QStringList files = QFileDialog::getOpenFileNames(_sessionDisplayConnection->view(), + QStringList files = QFileDialog::getOpenFileNames(view(), i18n("Select Files for ZModem Upload"), QDir::homePath()); if (!files.isEmpty()) { - _sessionDisplayConnection->session()->startZModem(zmodem, QString(), files); + session()->startZModem(zmodem, QString(), files); } } @@ -1937,8 +1935,8 @@ bool SessionController::isKonsolePart() const QString SessionController::userTitle() const { - if (!_sessionDisplayConnection->session().isNull()) { - return _sessionDisplayConnection->session()->userTitle(); + if (!session().isNull()) { + return session()->userTitle(); } else { return QString(); } diff --git a/src/session/SessionController.h b/src/session/SessionController.h index d9846b19..2da833fa 100644 --- a/src/session/SessionController.h +++ b/src/session/SessionController.h @@ -84,13 +84,13 @@ public: ~SessionController() override; /** Returns the session associated with this controller */ - QPointer session() + QPointer session() const { return _sessionDisplayConnection->session(); } /** Returns the view associated with this controller */ - QPointer view() + QPointer view() const { return _sessionDisplayConnection->view(); }