| 105 | #include <iostream> |
| 106 | |
| 107 | void SSHManagerPlugin::activeViewChanged(Konsole::SessionController *controller, Konsole::MainWindow *mainWindow) |
| 108 | { |
| 109 | Q_ASSERT(controller); |
| 110 | Q_ASSERT(mainWindow); |
| 111 | |
| 112 | auto terminalDisplay = controller->view(); |
| 113 | |
| 114 | d->showQuickAccess->deleteLater(); |
| 115 | d->showQuickAccess = new QAction(i18n("Show Quick Access for SSH Actions")); |
| 116 | |
| 117 | QSettings settings; |
| 118 | settings.beginGroup(QStringLiteral("plugins")); |
| 119 | settings.beginGroup(QStringLiteral("sshplugin")); |
| 120 | |
| 121 | const QKeySequence def(Qt::CTRL | Qt::ALT | Qt::Key_H); |
| 122 | const QString defText = def.toString(); |
| 123 | const QString entry = settings.value(QStringLiteral("ssh_shortcut"), defText).toString(); |
| 124 | const QKeySequence shortcutEntry(entry); |
| 125 | |
| 126 | mainWindow->actionCollection()->setDefaultShortcut(d->showQuickAccess, shortcutEntry); |
| 127 | terminalDisplay->addAction(d->showQuickAccess); |
| 128 | |
| 129 | connect(d->showQuickAccess, &QAction::triggered, this, [this, terminalDisplay, controller] { |
| 130 | auto bar = new KCommandBar(terminalDisplay->topLevelWidget()); |
| 131 | QList<QAction *> actions; |
| 132 | for (int i = 0; i < d->model.rowCount(); i++) { |
| 133 | QModelIndex folder = d->model.index(i, 0); |
| 134 | for (int e = 0; e < d->model.rowCount(folder); e++) { |
| 135 | QModelIndex idx = d->model.index(e, 0, folder); |
| 136 | QAction *act = new QAction(idx.data().toString()); |
| 137 | connect(act, &QAction::triggered, this, [this, idx, controller] { |
| 138 | requestConnection(nullptr, &d->model, controller, idx); |
| 139 | }); |
| 140 | actions.append(act); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if (actions.isEmpty()) // no ssh config found, must give feedback to the user about that |
| 145 | { |
| 146 | const QString feedbackMessage = i18n("No saved SSH config found. You can add one on Plugins -> SSH Manager"); |
| 147 | const QString feedbackTitle = i18n("Plugins - SSH Manager"); |
| 148 | KMessageBox::error(terminalDisplay->topLevelWidget(), feedbackMessage, feedbackTitle); |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | QVector<KCommandBar::ActionGroup> groups; |
| 153 | groups.push_back(KCommandBar::ActionGroup{i18n("SSH Entries"), actions}); |
| 154 | bar->setActions(groups); |
| 155 | bar->show(); |
| 156 | }); |
| 157 | |
| 158 | if (mainWindow) { |
| 159 | d->widgetForWindow[mainWindow]->setCurrentController(controller); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void SSHManagerPlugin::requestConnection(QSortFilterProxyModel *filterModel, |
| 164 | QStandardItemModel *model, |