Skip to content

Commit 36ec6e5

Browse files
committed
add ssh settings page
you can edit you devices, copy your ssh key and select you ssh binary on this page device are stored directly in a KConfigGroup, the deviceList property of Settings is only there to pass the devices around to other widgets
1 parent e00c38b commit 36ec6e5

File tree

6 files changed

+321
-0
lines changed

6 files changed

+321
-0
lines changed

src/recordhost.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
enum class RecordType
1515
{
1616
LaunchApplication,
17+
LaunchRemoteApplication,
1718
AttachToProcess,
1819
ProfileSystem,
1920
NUM_RECORD_TYPES

src/settings.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ void Settings::loadFromFile()
230230
connect(this, &Settings::lastUsedEnvironmentChanged, this, [sharedConfig](const QString& envName) {
231231
sharedConfig->group("PerfPaths").writeEntry("lastUsed", envName);
232232
});
233+
234+
setSSHPath(sharedConfig->group("SSH").readEntry("ssh"));
235+
setSSHCopyKeyPath(sharedConfig->group("SSH").readEntry("ssh-copy-id"));
236+
237+
connect(this, &Settings::sshPathChanged, this,
238+
[sharedConfig](const QString& path) { sharedConfig->group("SSH").writeEntry("ssh", path); });
239+
connect(this, &Settings::sshCopyIdPathChanged, this,
240+
[sharedConfig](const QString& path) { sharedConfig->group("SSH").writeEntry("ssh-copy-id", path); });
233241
}
234242

235243
void Settings::setSourceCodePaths(const QString& paths)
@@ -247,3 +255,27 @@ void Settings::setPerfPath(const QString& path)
247255
emit perfPathChanged(m_perfPath);
248256
}
249257
}
258+
259+
void Settings::setSSHPath(const QString& sshPath)
260+
{
261+
if (m_sshPath != sshPath) {
262+
m_sshPath = sshPath;
263+
emit sshPathChanged(m_sshPath);
264+
}
265+
}
266+
267+
void Settings::setSSHCopyKeyPath(const QString& sshCopyIdPath)
268+
{
269+
if (m_sshCopyIdPath != sshCopyIdPath) {
270+
m_sshCopyIdPath = sshCopyIdPath;
271+
emit sshCopyIdPathChanged(m_sshCopyIdPath);
272+
}
273+
}
274+
275+
void Settings::setDevices(const QStringList& devices)
276+
{
277+
if (m_devices != devices) {
278+
m_devices = devices;
279+
emit devicesChanged(m_devices);
280+
}
281+
}

src/settings.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ class Settings : public QObject
149149
return m_perfPath;
150150
}
151151

152+
QString sshPath() const
153+
{
154+
return m_sshPath;
155+
}
156+
157+
QString sshCopyIdPath() const
158+
{
159+
return m_sshCopyIdPath;
160+
}
161+
162+
QStringList devices() const
163+
{
164+
return m_devices;
165+
}
166+
152167
void loadFromFile();
153168

154169
signals:
@@ -170,6 +185,9 @@ class Settings : public QObject
170185
void lastUsedEnvironmentChanged(const QString& envName);
171186
void sourceCodePathsChanged(const QString& paths);
172187
void perfPathChanged(const QString& perfPath);
188+
void sshPathChanged(const QString& sshPath);
189+
void sshCopyIdPathChanged(const QString& sshCopyIdPath);
190+
void devicesChanged(const QStringList& devices);
173191

174192
public slots:
175193
void setPrettifySymbols(bool prettifySymbols);
@@ -192,6 +210,9 @@ public slots:
192210
void setLastUsedEnvironment(const QString& envName);
193211
void setSourceCodePaths(const QString& paths);
194212
void setPerfPath(const QString& path);
213+
void setSSHPath(const QString& path);
214+
void setSSHCopyKeyPath(const QString& path);
215+
void setDevices(const QStringList& devices);
195216

196217
private:
197218
Settings() = default;
@@ -223,4 +244,8 @@ public slots:
223244
QColor m_callgraphColor;
224245

225246
QString m_perfPath;
247+
QString m_sshPath;
248+
QString m_sshCopyIdPath;
249+
250+
QStringList m_devices;
226251
};

src/settingsdialog.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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"
@@ -26,6 +27,7 @@
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

7781
SettingsDialog::~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+
}

src/settingsdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class DebuginfodPage;
1919
class CallgraphSettingsPage;
2020
class SourcePathSettingsPage;
2121
class PerfSettingsPage;
22+
class SSHSettingsPage;
2223
}
2324

2425
class MultiConfigWidget;
@@ -50,11 +51,13 @@ class SettingsDialog : public KPageDialog
5051
void addDebuginfodPage();
5152
void addCallgraphPage();
5253
void addSourcePathPage();
54+
void addSSHPage();
5355

5456
std::unique_ptr<Ui::PerfSettingsPage> perfPage;
5557
std::unique_ptr<Ui::UnwindSettingsPage> unwindPage;
5658
std::unique_ptr<Ui::FlamegraphSettingsPage> flamegraphPage;
5759
std::unique_ptr<Ui::DebuginfodPage> debuginfodPage;
5860
std::unique_ptr<Ui::SourcePathSettingsPage> sourcePathPage;
5961
std::unique_ptr<Ui::CallgraphSettingsPage> callgraphPage;
62+
std::unique_ptr<Ui::SSHSettingsPage> sshSettingsPage;
6063
};

0 commit comments

Comments
 (0)