RemoteLinux: Inline sshkeycreationdialog.ui

Change-Id: Ie7c51a11c95ff0b484728741408df9173bc0e19f
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
hjk
2022-07-14 17:45:14 +02:00
parent f078319feb
commit a55e3d3889
5 changed files with 77 additions and 279 deletions

View File

@@ -31,7 +31,7 @@ add_qtc_plugin(RemoteLinux
remotelinuxrunconfiguration.cpp remotelinuxrunconfiguration.h remotelinuxrunconfiguration.cpp remotelinuxrunconfiguration.h
remotelinuxsignaloperation.cpp remotelinuxsignaloperation.h remotelinuxsignaloperation.cpp remotelinuxsignaloperation.h
rsyncdeploystep.cpp rsyncdeploystep.h rsyncdeploystep.cpp rsyncdeploystep.h
sshkeycreationdialog.cpp sshkeycreationdialog.h sshkeycreationdialog.ui sshkeycreationdialog.cpp sshkeycreationdialog.h
sshprocessinterface.h sshprocessinterface.h
tarpackagecreationstep.cpp tarpackagecreationstep.h tarpackagecreationstep.cpp tarpackagecreationstep.h
tarpackagedeploystep.cpp tarpackagedeploystep.h tarpackagedeploystep.cpp tarpackagedeploystep.h

View File

@@ -69,7 +69,6 @@ Project {
"rsyncdeploystep.h", "rsyncdeploystep.h",
"sshkeycreationdialog.cpp", "sshkeycreationdialog.cpp",
"sshkeycreationdialog.h", "sshkeycreationdialog.h",
"sshkeycreationdialog.ui",
"sshprocessinterface.h", "sshprocessinterface.h",
"tarpackagecreationstep.cpp", "tarpackagecreationstep.cpp",
"tarpackagecreationstep.h", "tarpackagecreationstep.h",

View File

@@ -24,16 +24,22 @@
****************************************************************************/ ****************************************************************************/
#include "sshkeycreationdialog.h" #include "sshkeycreationdialog.h"
#include "ui_sshkeycreationdialog.h"
#include <projectexplorer/devicesupport/sshsettings.h> #include <projectexplorer/devicesupport/sshsettings.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/layoutbuilder.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <QApplication> #include <QApplication>
#include <QComboBox>
#include <QDialog>
#include <QGroupBox>
#include <QLabel>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QStandardPaths> #include <QStandardPaths>
using namespace ProjectExplorer; using namespace ProjectExplorer;
@@ -42,40 +48,73 @@ using namespace Utils;
namespace RemoteLinux { namespace RemoteLinux {
SshKeyCreationDialog::SshKeyCreationDialog(QWidget *parent) SshKeyCreationDialog::SshKeyCreationDialog(QWidget *parent)
: QDialog(parent), m_ui(new Ui::SshKeyCreationDialog) : QDialog(parent)
{ {
m_ui->setupUi(this); setWindowTitle(tr("SSH Key Configuration"));
m_ui->privateKeyFileButton->setText(Utils::PathChooser::browseButtonLabel()); resize(385, 231);
m_rsa = new QRadioButton(tr("&RSA"));
m_rsa->setChecked(true);
m_ecdsa = new QRadioButton(tr("ECDSA"));
m_comboBox = new QComboBox;
m_privateKeyFileValueLabel = new QLabel;
m_publicKeyFileLabel = new QLabel;
auto privateKeyFileButton = new QPushButton(PathChooser::browseButtonLabel());
m_generateButton = new QPushButton(tr("&Generate And Save Key Pair"));
auto closeButton = new QPushButton(tr("&Cancel"));
using namespace Layouting;
const Break nl;
const Stretch st;
Column {
Group {
Title(tr("Options")),
Form {
tr("Key algorithm:"), m_rsa, m_ecdsa, st, nl,
tr("Key &size:"), m_comboBox, st, nl,
tr("Private key file:"), m_privateKeyFileValueLabel, privateKeyFileButton, st, nl,
tr("Public key file:"), m_publicKeyFileLabel
}
},
Stretch(),
Row { m_generateButton, closeButton, st }
}.attachTo(this);
const QString defaultPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) const QString defaultPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
+ QLatin1String("/.ssh/qtc_id"); + QLatin1String("/.ssh/qtc_id");
setPrivateKeyFile(FilePath::fromString(defaultPath)); setPrivateKeyFile(FilePath::fromString(defaultPath));
connect(m_ui->rsa, &QRadioButton::toggled, connect(closeButton, &QPushButton::clicked,
this, &QDialog::close);
connect(m_rsa, &QRadioButton::toggled,
this, &SshKeyCreationDialog::keyTypeChanged); this, &SshKeyCreationDialog::keyTypeChanged);
connect(m_ui->privateKeyFileButton, &QPushButton::clicked, connect(privateKeyFileButton, &QPushButton::clicked,
this, &SshKeyCreationDialog::handleBrowseButtonClicked); this, &SshKeyCreationDialog::handleBrowseButtonClicked);
connect(m_ui->generateButton, &QPushButton::clicked, connect(m_generateButton, &QPushButton::clicked,
this, &SshKeyCreationDialog::generateKeys); this, &SshKeyCreationDialog::generateKeys);
keyTypeChanged(); keyTypeChanged();
} }
SshKeyCreationDialog::~SshKeyCreationDialog() SshKeyCreationDialog::~SshKeyCreationDialog() = default;
{
delete m_ui;
}
void SshKeyCreationDialog::keyTypeChanged() void SshKeyCreationDialog::keyTypeChanged()
{ {
m_ui->comboBox->clear(); m_comboBox->clear();
QStringList keySizes; QStringList keySizes;
if (m_ui->rsa->isChecked()) if (m_rsa->isChecked())
keySizes << QLatin1String("1024") << QLatin1String("2048") << QLatin1String("4096"); keySizes << QLatin1String("1024") << QLatin1String("2048") << QLatin1String("4096");
else if (m_ui->ecdsa->isChecked()) else if (m_ecdsa->isChecked())
keySizes << QLatin1String("256") << QLatin1String("384") << QLatin1String("521"); keySizes << QLatin1String("256") << QLatin1String("384") << QLatin1String("521");
m_ui->comboBox->addItems(keySizes); m_comboBox->addItems(keySizes);
if (!keySizes.isEmpty()) if (!keySizes.isEmpty())
m_ui->comboBox->setCurrentIndex(0); m_comboBox->setCurrentIndex(0);
m_ui->comboBox->setEnabled(!keySizes.isEmpty()); m_comboBox->setEnabled(!keySizes.isEmpty());
} }
void SshKeyCreationDialog::generateKeys() void SshKeyCreationDialog::generateKeys()
@@ -89,10 +128,10 @@ void SshKeyCreationDialog::generateKeys()
.arg(privateKeyFilePath().toUserOutput())); .arg(privateKeyFilePath().toUserOutput()));
return; return;
} }
const QString keyTypeString = QLatin1String(m_ui->rsa->isChecked() ? "rsa": "ecdsa"); const QString keyTypeString = QLatin1String(m_rsa->isChecked() ? "rsa": "ecdsa");
QApplication::setOverrideCursor(Qt::BusyCursor); QApplication::setOverrideCursor(Qt::BusyCursor);
QtcProcess keygen; QtcProcess keygen;
const QStringList args{"-t", keyTypeString, "-b", m_ui->comboBox->currentText(), const QStringList args{"-t", keyTypeString, "-b", m_comboBox->currentText(),
"-N", QString(), "-f", privateKeyFilePath().path()}; "-N", QString(), "-f", privateKeyFilePath().path()};
QString errorMsg; QString errorMsg;
keygen.setCommand({SshSettings::keygenFilePath(), args}); keygen.setCommand({SshSettings::keygenFilePath(), args});
@@ -118,9 +157,9 @@ void SshKeyCreationDialog::handleBrowseButtonClicked()
void SshKeyCreationDialog::setPrivateKeyFile(const FilePath &filePath) void SshKeyCreationDialog::setPrivateKeyFile(const FilePath &filePath)
{ {
m_ui->privateKeyFileValueLabel->setText(filePath.toUserOutput()); m_privateKeyFileValueLabel->setText(filePath.toUserOutput());
m_ui->generateButton->setEnabled(!privateKeyFilePath().isEmpty()); m_generateButton->setEnabled(!privateKeyFilePath().isEmpty());
m_ui->publicKeyFileLabel->setText(filePath.toUserOutput() + ".pub"); m_publicKeyFileLabel->setText(filePath.toUserOutput() + ".pub");
} }
void SshKeyCreationDialog::showError(const QString &details) void SshKeyCreationDialog::showError(const QString &details)
@@ -130,12 +169,12 @@ void SshKeyCreationDialog::showError(const QString &details)
FilePath SshKeyCreationDialog::privateKeyFilePath() const FilePath SshKeyCreationDialog::privateKeyFilePath() const
{ {
return FilePath::fromUserInput(m_ui->privateKeyFileValueLabel->text()); return FilePath::fromUserInput(m_privateKeyFileValueLabel->text());
} }
FilePath SshKeyCreationDialog::publicKeyFilePath() const FilePath SshKeyCreationDialog::publicKeyFilePath() const
{ {
return FilePath::fromUserInput(m_ui->publicKeyFileLabel->text()); return FilePath::fromUserInput(m_publicKeyFileLabel->text());
} }
} // namespace RemoteLinux } // namespace RemoteLinux

View File

@@ -27,12 +27,17 @@
#include <QDialog> #include <QDialog>
QT_BEGIN_NAMESPACE
class QComboBox;
class QLabel;
class QPushButton;
class QRadioButton;
QT_END_NAMESPACE
namespace Utils { class FilePath; } namespace Utils { class FilePath; }
namespace RemoteLinux { namespace RemoteLinux {
namespace Ui { class SshKeyCreationDialog; }
class SshKeyCreationDialog : public QDialog class SshKeyCreationDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
@@ -51,7 +56,12 @@ private:
void showError(const QString &details); void showError(const QString &details);
private: private:
Ui::SshKeyCreationDialog *m_ui; QComboBox *m_comboBox;
QLabel *m_privateKeyFileValueLabel;
QLabel *m_publicKeyFileLabel;
QPushButton *m_generateButton;
QRadioButton *m_rsa;
QRadioButton *m_ecdsa;
}; };
} // namespace RemoteLinux } // namespace RemoteLinux

View File

@@ -1,250 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RemoteLinux::SshKeyCreationDialog</class>
<widget class="QDialog" name="RemoteLinux::SshKeyCreationDialog">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>385</width>
<height>231</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>SSH Key Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Options</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="keyAlgo">
<property name="text">
<string>Key algorithm:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="rsa">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;RSA</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="ecdsa">
<property name="text">
<string>ECDSA</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="keySize">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Key &amp;size:</string>
</property>
<property name="buddy">
<cstring>comboBox</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="comboBox"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="privateKeyFileLabel">
<property name="text">
<string>Private key file:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="privateKeyFileValueLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="privateKeyFileButton">
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Public key file:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="publicKeyFileLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="generateButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Generate And Save Key Pair</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>closeButton</sender>
<signal>clicked()</signal>
<receiver>RemoteLinux::SshKeyCreationDialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>195</x>
<y>184</y>
</hint>
<hint type="destinationlabel">
<x>381</x>
<y>107</y>
</hint>
</hints>
</connection>
</connections>
</ui>