Commit 44fd6c0b authored by Tomaz  Canabrava's avatar Tomaz Canabrava
Browse files

Revert "Uses SessionDisplayConnection to connect sessions and displays."

This reverts commit 6971d531.
parent 0f656a32
......@@ -29,7 +29,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"
......@@ -43,7 +42,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),
......@@ -81,15 +80,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();
......@@ -444,14 +434,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);
......@@ -480,14 +465,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;
......@@ -663,7 +642,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);
......@@ -688,7 +667,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);
......@@ -790,14 +769,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();
}
}
......@@ -849,8 +825,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);
}
}
......@@ -858,13 +834,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);
}
}
}
......
......@@ -30,7 +30,6 @@ class TabbedViewContainer;
class TerminalDisplay;
class ViewProperties;
class ViewSplitter;
class SessionDisplayConnection;
/**
* Manages the terminal display widgets in a Konsole window or part.
......@@ -164,7 +163,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
......@@ -416,9 +418,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