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 ;
@@ -262,3 +266,73 @@ void SettingsDialog::addSourcePathPage()
262266 Settings::instance ()->setSourceCodePaths (sourcePathPage->sourcePaths ->items ().join (colon));
263267 });
264268}
269+
270+ void SettingsDialog::addSSHPage ()
271+ {
272+ auto page = new QWidget (this );
273+ auto item = addPage (page, tr (" SSH Settings" ));
274+ item->setHeader (tr (" SSH Settings Page" ));
275+ item->setIcon (QIcon::fromTheme (QStringLiteral (" preferences-system-windows-behavior" )));
276+ sshSettingsPage->setupUi (page);
277+ sshSettingsPage->messageWidget ->hide ();
278+ sshSettingsPage->errorWidget ->hide ();
279+
280+ auto configGroup = KSharedConfig::openConfig ()->group (" SSH" );
281+ sshSettingsPage->deviceConfig ->setChildWidget (
282+ sshSettingsPage->deviceSettings ,
283+ {sshSettingsPage->username , sshSettingsPage->hostname , sshSettingsPage->options });
284+ sshSettingsPage->deviceConfig ->setConfigGroup (configGroup);
285+
286+ connect (sshSettingsPage->copySshKeyButton , &QPushButton::pressed, this , [this ] {
287+ auto * copyKey = new QProcess (this );
288+
289+ auto path = sshSettingsPage->sshCopyIdPath ->text ();
290+ if (path.isEmpty ()) {
291+ path = QStandardPaths::findExecutable (QStringLiteral (" ssh-copy-id" ));
292+ }
293+ if (path.isEmpty ()) {
294+ sshSettingsPage->messageWidget ->setText (tr (" Could not find ssh-copy-id" ));
295+ sshSettingsPage->messageWidget ->show ();
296+ return ;
297+ }
298+
299+ if (qEnvironmentVariableIsSet (" SSH_ASKPASS" )) {
300+ auto env = QProcessEnvironment::systemEnvironment ();
301+ env.insert (QStringLiteral (" SSH_ASKPASS" ), QString::fromUtf8 (qgetenv (" SSH_ASKPASS" )));
302+ copyKey->setProcessEnvironment (env);
303+ }
304+
305+ copyKey->setProgram (path);
306+
307+ QStringList arguments = {};
308+ auto options = sshSettingsPage->options ->text ();
309+ if (!options.isEmpty ()) {
310+ arguments.append (options.split (QLatin1Char (' ' )));
311+ }
312+ arguments.append (
313+ QStringLiteral (" %1@%2" ).arg (sshSettingsPage->username ->text (), sshSettingsPage->hostname ->text ()));
314+ copyKey->setArguments (arguments);
315+
316+ connect (copyKey, qOverload<int , QProcess::ExitStatus>(&QProcess::finished), this ,
317+ [this , copyKey](int code, QProcess::ExitStatus) {
318+ if (code == 0 ) {
319+ sshSettingsPage->messageWidget ->setText (QStringLiteral (" Copy key successfully" ));
320+ sshSettingsPage->messageWidget ->show ();
321+ } else {
322+ sshSettingsPage->errorWidget ->setText (QStringLiteral (" Failed to copy key" ));
323+ sshSettingsPage->errorWidget ->show ();
324+ }
325+ copyKey->deleteLater ();
326+ });
327+ copyKey->start ();
328+ });
329+
330+ connect (buttonBox (), &QDialogButtonBox::accepted, this , [this , configGroup] {
331+ sshSettingsPage->deviceConfig ->saveCurrentConfig ();
332+
333+ auto settings = Settings::instance ();
334+ settings->setDevices (configGroup.groupList ());
335+ settings->setSSHPath (sshSettingsPage->sshBinary ->text ());
336+ settings->setSSHCopyKeyPath (sshSettingsPage->sshCopyIdPath ->text ());
337+ });
338+ }
0 commit comments