diff --git a/src/plugins/SSHManager/sshmanagermodel.cpp b/src/plugins/SSHManager/sshmanagermodel.cpp index e9ce7812..27b4943f 100644 --- a/src/plugins/SSHManager/sshmanagermodel.cpp +++ b/src/plugins/SSHManager/sshmanagermodel.cpp @@ -99,6 +99,28 @@ void SSHManagerModel::addChildItem(const SSHConfigurationData &config, const QSt parentItem->sortChildren(0); } +std::optional SSHManagerModel::profileForHost(const QString &host) const +{ + auto *root = invisibleRootItem(); + + // iterate through folders: + for (int i = 0, end = root->rowCount(); i < end; ++i) { + // iterate throguh the items on folders; + auto folder = root->child(i); + for (int e = 0, inner_end = folder->rowCount(); e < inner_end; ++e) { + QStandardItem *ssh_item = folder->child(e); + auto data = ssh_item->data(SSHRole).value(); + + // Return the profile name if the host matches. + if (data.host == host) { + return data.profileName; + } + } + } + + return {}; +} + bool SSHManagerModel::setData(const QModelIndex &index, const QVariant &value, int role) { const bool ret = QStandardItemModel::setData(index, value, role); diff --git a/src/plugins/SSHManager/sshmanagermodel.h b/src/plugins/SSHManager/sshmanagermodel.h index 4de5326e..cf011123 100644 --- a/src/plugins/SSHManager/sshmanagermodel.h +++ b/src/plugins/SSHManager/sshmanagermodel.h @@ -12,6 +12,7 @@ #include #include +#include namespace Konsole { @@ -54,6 +55,7 @@ public: void save(); bool hasHost(const QString &hostName) const; + std::optional profileForHost(const QString &host) const; private: QStandardItem *m_sshConfigTopLevelItem = nullptr;