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

Connect the active Session to the SSHModel

This is needed so we can later on react to hostname changes to
set the active profile.
parent 23a34007
......@@ -21,6 +21,8 @@
#include <QTextStream>
#include "profile/ProfileManager.h"
#include "session/Session.h"
#include "session/SessionController.h"
#include "sshconfigurationdata.h"
Q_LOGGING_CATEGORY(SshManagerPlugin, "org.kde.konsole.plugin.sshmanager")
......@@ -137,6 +139,22 @@ bool SSHManagerModel::hasHost(const QString &host) const
return false;
}
void SSHManagerModel::setSessionController(Konsole::SessionController *controller)
{
if (m_session) {
disconnect(m_session, nullptr, this, nullptr);
}
m_session = controller->session();
Q_ASSERT(m_session);
connect(m_session, &Konsole::Session::hostnameChanged, this, &SSHManagerModel::triggerProfileChange);
}
void SSHManagerModel::triggerProfileChange(const QString &sshHost)
{
Q_UNUSED(sshHost);
}
void SSHManagerModel::load()
{
auto config = KConfig(QStringLiteral("konsolesshconfig"), KConfig::OpenFlag::SimpleConfig);
......
......@@ -13,6 +13,12 @@
#include <memory>
namespace Konsole
{
class SessionController;
class Session;
}
class SSHConfigurationData;
class SSHManagerModel : public QStandardItemModel
......@@ -26,6 +32,13 @@ public:
SSHManagerModel(QObject *parent = nullptr);
~SSHManagerModel() override;
void setSessionController(Konsole::SessionController *controller);
/** Connected to Session::hostnameChanged, tries to set the profile to
* the current configured profile for the specified SSH host
*/
Q_SLOT void triggerProfileChange(const QString &sshHost);
QStandardItem *addTopLevelItem(const QString &toplevel);
void addChildItem(const SSHConfigurationData &config, const QString &parentName);
void editChildItem(const SSHConfigurationData &config, const QModelIndex &idx);
......@@ -45,6 +58,7 @@ public:
private:
QStandardItem *m_sshConfigTopLevelItem = nullptr;
QFileSystemWatcher m_sshConfigWatcher;
Konsole::Session *m_session = nullptr;
};
#endif
......@@ -329,7 +329,9 @@ void SSHManagerTreeWidget::setModel(SSHManagerModel *model)
void SSHManagerTreeWidget::setCurrentController(Konsole::SessionController *controller)
{
qCDebug(KonsoleDebug) << "Controller changed to" << controller;
d->controller = controller;
d->model->setSessionController(controller);
}
std::pair<bool, QString> SSHManagerTreeWidget::checkFields() const
......
......@@ -751,6 +751,12 @@ Q_SIGNALS:
*/
void getBackgroundColor(uint terminator);
/**
* When a user enters a ssh session that changes where the `hostname` is
* this is emmited.
*/
void hostnameChanged(const QString &hostname);
private Q_SLOTS:
void done(int, QProcess::ExitStatus);
......
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