Commit 1b03adf7 authored by Tomaz  Canabrava's avatar Tomaz Canabrava Committed by Kurt Hindenburg
Browse files

Revert "Uses SessionDisplayConnection to connect sessions and displays."

This reverts commit 6971d531.

(cherry picked from commit 44fd6c0b)
parent adc6f2ed
......@@ -42,7 +42,6 @@
#include "session/Session.h"
#include "session/SessionController.h"
#include "session/SessionManager.h"
#include "session/SessionDisplayConnection.h"
#include "terminalDisplay/TerminalDisplay.h"
#include "widgets/ViewContainer.h"
......@@ -56,7 +55,7 @@ ViewManager::ViewManager(QObject *parent, KActionCollection *collection) :
QObject(parent),
_viewContainer(nullptr),
_pluggedController(nullptr),
_sessionMap(QVector<SessionDisplayConnection *>()),
_sessionMap(QHash<TerminalDisplay *, Session *>()),
_actionCollection(collection),
_navigationMethod(NoNavigation),
_navigationVisibility(NavigationNotSet),
......@@ -94,15 +93,6 @@ int ViewManager::managerId() const
return _managerId;
}
QList<Session *> ViewManager::sessions()
{
QList<Session *> sessionList;
for (auto sdsp : _sessionMap) {
sessionList.append(sdsp->session());
}
return sessionList;
}
QWidget *ViewManager::activeView() const
{
return _viewContainer->currentWidget();
......@@ -457,14 +447,9 @@ Session* ViewManager::forgetTerminal(TerminalDisplay* terminal)
disconnect(terminal, &TerminalDisplay::requestToggleExpansion, nullptr, nullptr);
removeController(terminal->sessionController());
Session *session = nullptr;
for (auto sdsp : _sessionMap) {
session = sdsp->view() == terminal ? sdsp->session() : nullptr;
if (session != nullptr) {
_sessionMap.removeOne(sdsp);
disconnect(session, &Konsole::Session::finished, this, &Konsole::ViewManager::sessionFinished);
break;
}
auto session = _sessionMap.take(terminal);
if (session != nullptr) {
disconnect(session, &Konsole::Session::finished, this, &Konsole::ViewManager::sessionFinished);
}
_viewContainer->disconnectTerminalDisplay(terminal);
updateTerminalDisplayHistory(terminal, true);
......@@ -493,14 +478,8 @@ void ViewManager::sessionFinished()
auto *session = qobject_cast<Session *>(sender());
Q_ASSERT(session);
TerminalDisplay *view = nullptr;
for (auto sdsp : _sessionMap) {
view = sdsp->session() == session ? sdsp->view() : nullptr;
if (view != nullptr) {
_sessionMap.removeOne(sdsp);
break;
}
}
auto view = _sessionMap.key(session);
_sessionMap.remove(view);
if (SessionManager::instance()->isClosingAllSessions()){
return;
......@@ -676,7 +655,7 @@ void ViewManager::attachView(TerminalDisplay *terminal, Session *session)
connect(terminal, &TerminalDisplay::requestToggleExpansion,
_viewContainer, &TabbedViewContainer::toggleMaximizeCurrentTerminal, Qt::UniqueConnection);
_sessionMap.append(new SessionDisplayConnection(session, terminal, this));
_sessionMap[terminal] = session;
createController(session, terminal);
toggleActionsBasedOnState();
_terminalDisplayHistory.append(terminal);
......@@ -701,7 +680,7 @@ TerminalDisplay *ViewManager::createView(Session *session)
display->setSize(preferredSize.width(), preferredSize.height());
createController(session, display);
_sessionMap.append(new SessionDisplayConnection(session, display, this));
_sessionMap[display] = session;
session->addView(display);
_terminalDisplayHistory.append(display);
......@@ -803,14 +782,11 @@ void ViewManager::viewDestroyed(QWidget *view)
// 1. detach view from session
// 2. if the session has no views left, close it
Session *session = nullptr;
for (auto sdsp : _sessionMap) {
session = sdsp->view() == display ? sdsp->session() : nullptr;
_sessionMap.removeOne(sdsp);
if (session != nullptr) {
if (session->views().count() == 0) {
session->close();
}
Session *session = _sessionMap[ display ];
_sessionMap.remove(display);
if (session != nullptr) {
if (session->views().count() == 0) {
session->close();
}
}
......@@ -862,8 +838,8 @@ void ViewManager::updateViewsForSession(Session *session)
{
const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
for (auto sdsp : _sessionMap) {
TerminalDisplay *view = sdsp->session() ? sdsp->view() : nullptr;
const QList<TerminalDisplay *> sessionMapKeys = _sessionMap.keys(session);
for (TerminalDisplay *view : sessionMapKeys) {
applyProfileToView(view, profile);
}
}
......@@ -871,13 +847,15 @@ void ViewManager::updateViewsForSession(Session *session)
void ViewManager::profileChanged(const Profile::Ptr &profile)
{
// update all views associated with this profile
QVectorIterator<SessionDisplayConnection*> iter(_sessionMap);
QHashIterator<TerminalDisplay *, Session *> iter(_sessionMap);
while (iter.hasNext()) {
iter.next();
// if session uses this profile, update the display
SessionDisplayConnection *sdsp = iter.next();
if (sdsp != nullptr && SessionManager::instance()->sessionProfile(sdsp->session()) == profile) {
applyProfileToView(sdsp->view(), profile);
if (iter.key() != nullptr
&& iter.value() != nullptr
&& SessionManager::instance()->sessionProfile(iter.value()) == profile) {
applyProfileToView(iter.key(), profile);
}
}
}
......
......@@ -43,7 +43,6 @@ class TabbedViewContainer;
class TerminalDisplay;
class ViewProperties;
class ViewSplitter;
class SessionDisplayConnection;
/**
* Manages the terminal display widgets in a Konsole window or part.
......@@ -177,7 +176,10 @@ public:
int managerId() const;
/** Returns a list of sessions in this ViewManager */
QList<Session *> sessions();
QList<Session *> sessions()
{
return _sessionMap.values();
}
/**
* Returns whether the @p profile has the blur setting enabled
......@@ -429,9 +431,7 @@ private:
QPointer<TabbedViewContainer> _viewContainer;
QPointer<SessionController> _pluggedController;
// TODO: This map must be separated into a new class containing the global link map between sessions and displays used by the entire konsole
// The solution implemented so far is initial and should be reviewed
QVector<SessionDisplayConnection*> _sessionMap;
QHash<TerminalDisplay *, Session *> _sessionMap;
KActionCollection *_actionCollection;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment