1313#include " ui_flamegraphsettingspage.h"
1414#include " ui_perfsettingspage.h"
1515#include " ui_sourcepathsettings.h"
16+ #include " ui_sshsettingspage.h"
1617#include " ui_unwindsettingspage.h"
1718
1819#include " multiconfigwidget.h"
2627#include < QKeyEvent>
2728#include < QLineEdit>
2829#include < QListView>
30+ #include < QProcess>
2931
3032#include < hotspot-config.h>
3133
@@ -63,6 +65,7 @@ SettingsDialog::SettingsDialog(QWidget* parent)
6365#if KGraphViewerPart_FOUND
6466 , callgraphPage(new Ui::CallgraphSettingsPage)
6567#endif
68+ , sshSettingsPage(new Ui::SSHSettingsPage)
6669{
6770 addPerfSettingsPage ();
6871 addPathSettingsPage ();
@@ -72,6 +75,7 @@ SettingsDialog::SettingsDialog(QWidget* parent)
7275 addCallgraphPage ();
7376#endif
7477 addSourcePathPage ();
78+ addSSHPage ();
7579}
7680
7781SettingsDialog::~SettingsDialog () = default ;
@@ -259,3 +263,71 @@ void SettingsDialog::addSourcePathPage()
259263 Settings::instance ()->setSourceCodePaths (sourcePathPage->sourcePaths ->items ().join (colon));
260264 });
261265}
266+
267+ void SettingsDialog::addSSHPage ()
268+ {
269+ auto page = new QWidget (this );
270+ auto item = addPage (page, tr (" SSH Settings" ));
271+ item->setHeader (tr (" SSH Settings Page" ));
272+ item->setIcon (QIcon::fromTheme (QStringLiteral (" preferences-system-windows-behavior" )));
273+ sshSettingsPage->setupUi (page);
274+ sshSettingsPage->messageWidget ->hide ();
275+ sshSettingsPage->errorWidget ->hide ();
276+
277+ auto configGroup = KSharedConfig::openConfig ()->group (" SSH" );
278+ sshSettingsPage->deviceConfig ->setChildWidget (sshSettingsPage->deviceSettings );
279+ sshSettingsPage->deviceConfig ->setConfigGroup (configGroup);
280+
281+ connect (sshSettingsPage->copySshKeyButton , &QPushButton::pressed, this , [this ] {
282+ auto * copyKey = new QProcess (this );
283+
284+ auto path = sshSettingsPage->sshCopyIdPath ->text ();
285+ if (path.isEmpty ()) {
286+ path = QStandardPaths::findExecutable (QStringLiteral (" ssh-copy-id" ));
287+ }
288+ if (path.isEmpty ()) {
289+ sshSettingsPage->messageWidget ->setText (tr (" Could not find ssh-copy-id" ));
290+ sshSettingsPage->messageWidget ->show ();
291+ return ;
292+ }
293+
294+ if (qEnvironmentVariableIsSet (" SSH_ASKPASS" )) {
295+ auto env = QProcessEnvironment::systemEnvironment ();
296+ env.insert (QStringLiteral (" SSH_ASKPASS" ), QString::fromUtf8 (qgetenv (" SSH_ASKPASS" )));
297+ copyKey->setProcessEnvironment (env);
298+ }
299+
300+ copyKey->setProgram (path);
301+
302+ QStringList arguments = {};
303+ auto options = sshSettingsPage->options ->text ();
304+ if (!options.isEmpty ()) {
305+ arguments.append (options.split (QLatin1Char (' ' )));
306+ }
307+ arguments.append (
308+ QStringLiteral (" %1@%2" ).arg (sshSettingsPage->username ->text (), sshSettingsPage->hostname ->text ()));
309+ copyKey->setArguments (arguments);
310+
311+ connect (copyKey, qOverload<int , QProcess::ExitStatus>(&QProcess::finished), this ,
312+ [this , copyKey](int code, QProcess::ExitStatus) {
313+ if (code == 0 ) {
314+ sshSettingsPage->messageWidget ->setText (QStringLiteral (" Copy key successfully" ));
315+ sshSettingsPage->messageWidget ->show ();
316+ } else {
317+ sshSettingsPage->errorWidget ->setText (QStringLiteral (" Failed to copy key" ));
318+ sshSettingsPage->errorWidget ->show ();
319+ }
320+ copyKey->deleteLater ();
321+ });
322+ copyKey->start ();
323+ });
324+
325+ connect (buttonBox (), &QDialogButtonBox::accepted, this , [this , configGroup] {
326+ sshSettingsPage->deviceConfig ->saveCurrentConfig ();
327+
328+ auto settings = Settings::instance ();
329+ settings->setDevices (configGroup.groupList ());
330+ settings->setSSHPath (sshSettingsPage->sshBinary ->text ());
331+ settings->setSSHCopyKeyPath (sshSettingsPage->sshCopyIdPath ->text ());
332+ });
333+ }
0 commit comments