Skip to content

Commit 8bb0bf6

Browse files
committed
ssh step 1, settings + copy key
1 parent 4347576 commit 8bb0bf6

File tree

7 files changed

+252
-11
lines changed

7 files changed

+252
-11
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/recordpage.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "perfoutputwidgetkonsole.h"
4444
#include "perfoutputwidgettext.h"
4545
#include "perfrecord.h"
46+
#include "settings.h"
4647

4748
namespace {
4849
bool isIntel()
@@ -206,6 +207,12 @@ RecordPage::RecordPage(QWidget* parent)
206207
ui->multiConfig->saveCurrentConfig(); // TODO: set app params
207208
});
208209

210+
auto settings = Settings::instance();
211+
connect(settings, &Settings::devicesChanged, this, [this](const QStringList& devices) {
212+
ui->deviceComboBox->clear();
213+
ui->deviceComboBox->insertItems(0, devices);
214+
});
215+
209216
ui->compressionComboBox->addItem(tr("Disabled"), -1);
210217
ui->compressionComboBox->addItem(tr("Enabled (Default Level)"), 0);
211218
ui->compressionComboBox->addItem(tr("Level 1 (Fastest)"), 1);
@@ -288,6 +295,8 @@ RecordPage::RecordPage(QWidget* parent)
288295

289296
ui->recordTypeComboBox->addItem(QIcon::fromTheme(QStringLiteral("run-build")), tr("Launch Application"),
290297
QVariant::fromValue(RecordType::LaunchApplication));
298+
ui->recordTypeComboBox->addItem(QIcon::fromTheme(QStringLiteral("run-build")), tr("Launch Remote Application"),
299+
QVariant::fromValue(RecordType::LaunchRemoteApplication));
291300
ui->recordTypeComboBox->addItem(QIcon::fromTheme(QStringLiteral("run-install")), tr("Attach To Process(es)"),
292301
QVariant::fromValue(RecordType::AttachToProcess));
293302
ui->recordTypeComboBox->addItem(QIcon::fromTheme(QStringLiteral("run-build-install-root")), tr("Profile System"),
@@ -731,7 +740,9 @@ void RecordPage::updateRecordType()
731740
setError({});
732741

733742
const auto recordType = selectedRecordType(ui);
734-
ui->launchAppBox->setVisible(recordType == RecordType::LaunchApplication);
743+
ui->remoteDeviceBox->setVisible(recordType == RecordType::LaunchRemoteApplication);
744+
ui->launchAppBox->setVisible(recordType == RecordType::LaunchApplication
745+
|| recordType == RecordType::LaunchRemoteApplication);
735746
ui->attachAppBox->setVisible(recordType == RecordType::AttachToProcess);
736747

737748
m_perfOutput->setInputVisible(recordType == RecordType::LaunchApplication);

src/recordpage.ui

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@
4949
</item>
5050
</layout>
5151
</item>
52+
<item>
53+
<widget class="QGroupBox" name="remoteDeviceBox">
54+
<property name="title">
55+
<string>Remote Device</string>
56+
</property>
57+
<layout class="QFormLayout" name="formLayout_4">
58+
<item row="0" column="0">
59+
<widget class="QLabel" name="label">
60+
<property name="text">
61+
<string>Device:</string>
62+
</property>
63+
</widget>
64+
</item>
65+
<item row="0" column="1">
66+
<widget class="QComboBox" name="deviceComboBox"/>
67+
</item>
68+
</layout>
69+
</widget>
70+
</item>
5271
<item>
5372
<widget class="QGroupBox" name="launchAppBox">
5473
<property name="title">

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: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <QKeyEvent>
2828
#include <QLineEdit>
2929
#include <QListView>
30+
#include <QProcess>
3031

3132
#include <hotspot-config.h>
3233

@@ -74,7 +75,7 @@ SettingsDialog::SettingsDialog(QWidget* parent)
7475
addCallgraphPage();
7576
#endif
7677
addSourcePathPage();
77-
// addSSHPage();
78+
addSSHPage();
7879
}
7980

8081
SettingsDialog::~SettingsDialog() = default;
@@ -270,11 +271,63 @@ void SettingsDialog::addSSHPage()
270271
item->setHeader(tr("SSH Settings Page"));
271272
item->setIcon(QIcon::fromTheme(QStringLiteral("preferences-system-windows-behavior")));
272273
sshSettingsPage->setupUi(page);
274+
sshSettingsPage->messageWidget->hide();
275+
sshSettingsPage->errorWidget->hide();
273276

274-
auto widget = new QWidget(this);
275-
auto settings = new Ui::DeviceSettings;
276-
settings->setupUi(widget);
277277
auto configGroup = KSharedConfig::openConfig()->group("SSH");
278-
sshSettingsPage->deviceConfig->setConfigGroup(configGroup.group("devices"));
279-
sshSettingsPage->deviceConfig->setChildWidget(widget);
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+
});
280333
}

src/sshsettingspage.ui

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,80 @@
2929
<property name="bottomMargin">
3030
<number>0</number>
3131
</property>
32+
<item>
33+
<widget class="KMessageWidget" name="messageWidget"/>
34+
</item>
35+
<item>
36+
<widget class="KMessageWidget" name="errorWidget">
37+
<property name="messageType">
38+
<enum>KMessageWidget::Error</enum>
39+
</property>
40+
</widget>
41+
</item>
3242
<item>
3343
<widget class="MultiConfigWidget" name="deviceConfig" native="true"/>
3444
</item>
45+
<item>
46+
<widget class="QWidget" name="deviceSettings" native="true">
47+
<layout class="QFormLayout" name="formLayout_3">
48+
<property name="horizontalSpacing">
49+
<number>0</number>
50+
</property>
51+
<property name="verticalSpacing">
52+
<number>0</number>
53+
</property>
54+
<property name="leftMargin">
55+
<number>0</number>
56+
</property>
57+
<property name="topMargin">
58+
<number>0</number>
59+
</property>
60+
<property name="rightMargin">
61+
<number>0</number>
62+
</property>
63+
<property name="bottomMargin">
64+
<number>0</number>
65+
</property>
66+
<item row="0" column="0">
67+
<widget class="QLabel" name="hostnameLabel">
68+
<property name="text">
69+
<string>Hostname:</string>
70+
</property>
71+
</widget>
72+
</item>
73+
<item row="0" column="1">
74+
<widget class="QLineEdit" name="hostname"/>
75+
</item>
76+
<item row="1" column="0">
77+
<widget class="QLabel" name="usernameLabel">
78+
<property name="text">
79+
<string>Username:</string>
80+
</property>
81+
</widget>
82+
</item>
83+
<item row="1" column="1">
84+
<widget class="QLineEdit" name="username"/>
85+
</item>
86+
<item row="2" column="0">
87+
<widget class="QLabel" name="optionsLabel">
88+
<property name="text">
89+
<string>Options:</string>
90+
</property>
91+
</widget>
92+
</item>
93+
<item row="2" column="1">
94+
<widget class="QLineEdit" name="options"/>
95+
</item>
96+
<item row="3" column="1">
97+
<widget class="QPushButton" name="copySshKeyButton">
98+
<property name="text">
99+
<string>Copy SSH Key</string>
100+
</property>
101+
</widget>
102+
</item>
103+
</layout>
104+
</widget>
105+
</item>
35106
<item>
36107
<widget class="Line" name="line">
37108
<property name="orientation">
@@ -60,22 +131,51 @@
60131
<property name="bottomMargin">
61132
<number>0</number>
62133
</property>
63-
<item row="0" column="0">
134+
<item row="1" column="0">
135+
<widget class="QLabel" name="sshPath">
136+
<property name="text">
137+
<string>ssh:</string>
138+
</property>
139+
</widget>
140+
</item>
141+
<item row="1" column="1">
142+
<widget class="KUrlRequester" name="sshBinary">
143+
<property name="placeholderText">
144+
<string>ssh</string>
145+
</property>
146+
</widget>
147+
</item>
148+
<item row="2" column="0">
64149
<widget class="QLabel" name="label">
65150
<property name="text">
66-
<string>TextLabel</string>
151+
<string>ssh-copy-id:</string>
67152
</property>
68153
</widget>
69154
</item>
70-
<item row="0" column="1">
71-
<widget class="QLineEdit" name="lineEdit"/>
155+
<item row="2" column="1">
156+
<widget class="KUrlRequester" name="sshCopyIdPath">
157+
<property name="placeholderText">
158+
<string>ssh-copy-id</string>
159+
</property>
160+
</widget>
72161
</item>
73162
</layout>
74163
</widget>
75164
</item>
76165
</layout>
77166
</widget>
78167
<customwidgets>
168+
<customwidget>
169+
<class>KUrlRequester</class>
170+
<extends>QWidget</extends>
171+
<header>kurlrequester.h</header>
172+
</customwidget>
173+
<customwidget>
174+
<class>KMessageWidget</class>
175+
<extends>QFrame</extends>
176+
<header>kmessagewidget.h</header>
177+
<container>1</container>
178+
</customwidget>
79179
<customwidget>
80180
<class>MultiConfigWidget</class>
81181
<extends>QWidget</extends>

0 commit comments

Comments
 (0)