| 46 | }; |
| 47 | |
| 48 | SSHManagerTreeWidget::SSHManagerTreeWidget(QWidget *parent) |
| 49 | : QWidget(parent) |
| 50 | , ui(std::make_unique<Ui::SSHTreeWidget>()) |
| 51 | , d(std::make_unique<SSHManagerTreeWidget::Private>()) |
| 52 | { |
| 53 | ui->setupUi(this); |
| 54 | ui->errorPanel->hide(); |
| 55 | |
| 56 | d->filterModel = new SSHManagerFilterModel(this); |
| 57 | |
| 58 | // full port range, users can setup ssh on any port they want |
| 59 | const auto *portValidator = new QIntValidator(0, 65535, this); |
| 60 | ui->port->setValidator(portValidator); |
| 61 | |
| 62 | connect(ui->newSSHConfig, &QPushButton::clicked, this, &SSHManagerTreeWidget::showInfoPane); |
| 63 | connect(ui->btnCancel, &QPushButton::clicked, this, &SSHManagerTreeWidget::clearSshInfo); |
| 64 | connect(ui->btnEdit, &QPushButton::clicked, this, &SSHManagerTreeWidget::editSshInfo); |
| 65 | connect(ui->btnDelete, &QPushButton::clicked, this, &SSHManagerTreeWidget::triggerDelete); |
| 66 | connect(ui->btnInvertFilter, &QPushButton::clicked, d->filterModel, &SSHManagerFilterModel::setInvertFilter); |
| 67 | |
| 68 | connect(ui->btnFindSshKey, &QPushButton::clicked, this, [this] { |
| 69 | const QString homeFolder = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); |
| 70 | const QString sshFile = QFileDialog::getOpenFileName(this, i18n("SSH Key"), homeFolder + QStringLiteral("/.ssh")); |
| 71 | if (sshFile.isEmpty()) { |
| 72 | return; |
| 73 | } |
| 74 | ui->sshkey->setText(sshFile); |
| 75 | }); |
| 76 | |
| 77 | connect(ui->filterText, &QLineEdit::textChanged, this, [this] { |
| 78 | d->filterModel->setFilterRegularExpression(ui->filterText->text()); |
| 79 | d->filterModel->invalidate(); |
| 80 | }); |
| 81 | |
| 82 | connect(Konsole::ProfileModel::instance(), &Konsole::ProfileModel::rowsRemoved, this, &SSHManagerTreeWidget::updateProfileList); |
| 83 | connect(Konsole::ProfileModel::instance(), &Konsole::ProfileModel::rowsInserted, this, &SSHManagerTreeWidget::updateProfileList); |
| 84 | updateProfileList(); |
| 85 | |
| 86 | ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); |
| 87 | |
| 88 | connect(ui->treeView, &QTreeView::customContextMenuRequested, [this](const QPoint &pos) { |
| 89 | QModelIndex idx = ui->treeView->indexAt(pos); |
| 90 | if (!idx.isValid()) { |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | if (idx.data(Qt::DisplayRole) == i18n("SSH Config")) { |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | auto sourceIdx = d->filterModel->mapToSource(idx); |
| 99 | const bool isParent = sourceIdx.parent() == d->model->invisibleRootItem()->index(); |
| 100 | if (!isParent) { |
| 101 | const auto item = d->model->itemFromIndex(sourceIdx); |
| 102 | const auto data = item->data(SSHManagerModel::SSHRole).value<SSHConfigurationData>(); |
| 103 | if (data.importedFromSshConfig) { |
| 104 | return; |
| 105 | } |