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
remotelinuxsignaloperation.cpp remotelinuxsignaloperation.h
rsyncdeploystep.cpp rsyncdeploystep.h
sshkeycreationdialog.cpp sshkeycreationdialog.h sshkeycreationdialog.ui
sshkeycreationdialog.cpp sshkeycreationdialog.h
sshprocessinterface.h
tarpackagecreationstep.cpp tarpackagecreationstep.h
tarpackagedeploystep.cpp tarpackagedeploystep.h

View File

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

View File

@@ -24,16 +24,22 @@
****************************************************************************/
#include "sshkeycreationdialog.h"
#include "ui_sshkeycreationdialog.h"
#include <projectexplorer/devicesupport/sshsettings.h>
#include <utils/fileutils.h>
#include <utils/layoutbuilder.h>
#include <utils/pathchooser.h>
#include <utils/qtcprocess.h>
#include <QApplication>
#include <QComboBox>
#include <QDialog>
#include <QGroupBox>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QStandardPaths>
using namespace ProjectExplorer;
@@ -42,40 +48,73 @@ using namespace Utils;
namespace RemoteLinux {
SshKeyCreationDialog::SshKeyCreationDialog(QWidget *parent)
: QDialog(parent), m_ui(new Ui::SshKeyCreationDialog)
: QDialog(parent)
{
m_ui->setupUi(this);
m_ui->privateKeyFileButton->setText(Utils::PathChooser::browseButtonLabel());
setWindowTitle(tr("SSH Key Configuration"));
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)
+ QLatin1String("/.ssh/qtc_id");
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);
connect(m_ui->privateKeyFileButton, &QPushButton::clicked,
connect(privateKeyFileButton, &QPushButton::clicked,
this, &SshKeyCreationDialog::handleBrowseButtonClicked);
connect(m_ui->generateButton, &QPushButton::clicked,
connect(m_generateButton, &QPushButton::clicked,
this, &SshKeyCreationDialog::generateKeys);
keyTypeChanged();
}
SshKeyCreationDialog::~SshKeyCreationDialog()
{
delete m_ui;
}
SshKeyCreationDialog::~SshKeyCreationDialog() = default;
void SshKeyCreationDialog::keyTypeChanged()
{
m_ui->comboBox->clear();
m_comboBox->clear();
QStringList keySizes;
if (m_ui->rsa->isChecked())
if (m_rsa->isChecked())
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");
m_ui->comboBox->addItems(keySizes);
m_comboBox->addItems(keySizes);
if (!keySizes.isEmpty())
m_ui->comboBox->setCurrentIndex(0);
m_ui->comboBox->setEnabled(!keySizes.isEmpty());
m_comboBox->setCurrentIndex(0);
m_comboBox->setEnabled(!keySizes.isEmpty());
}
void SshKeyCreationDialog::generateKeys()
@@ -89,10 +128,10 @@ void SshKeyCreationDialog::generateKeys()
.arg(privateKeyFilePath().toUserOutput()));
return;
}
const QString keyTypeString = QLatin1String(m_ui->rsa->isChecked() ? "rsa": "ecdsa");
const QString keyTypeString = QLatin1String(m_rsa->isChecked() ? "rsa": "ecdsa");
QApplication::setOverrideCursor(Qt::BusyCursor);
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()};
QString errorMsg;
keygen.setCommand({SshSettings::keygenFilePath(), args});
@@ -118,9 +157,9 @@ void SshKeyCreationDialog::handleBrowseButtonClicked()
void SshKeyCreationDialog::setPrivateKeyFile(const FilePath &filePath)
{
m_ui->privateKeyFileValueLabel->setText(filePath.toUserOutput());
m_ui->generateButton->setEnabled(!privateKeyFilePath().isEmpty());
m_ui->publicKeyFileLabel->setText(filePath.toUserOutput() + ".pub");
m_privateKeyFileValueLabel->setText(filePath.toUserOutput());
m_generateButton->setEnabled(!privateKeyFilePath().isEmpty());
m_publicKeyFileLabel->setText(filePath.toUserOutput() + ".pub");
}
void SshKeyCreationDialog::showError(const QString &details)
@@ -130,12 +169,12 @@ void SshKeyCreationDialog::showError(const QString &details)
FilePath SshKeyCreationDialog::privateKeyFilePath() const
{
return FilePath::fromUserInput(m_ui->privateKeyFileValueLabel->text());
return FilePath::fromUserInput(m_privateKeyFileValueLabel->text());
}
FilePath SshKeyCreationDialog::publicKeyFilePath() const
{
return FilePath::fromUserInput(m_ui->publicKeyFileLabel->text());
return FilePath::fromUserInput(m_publicKeyFileLabel->text());
}
} // namespace RemoteLinux

View File

@@ -27,12 +27,17 @@
#include <QDialog>
QT_BEGIN_NAMESPACE
class QComboBox;
class QLabel;
class QPushButton;
class QRadioButton;
QT_END_NAMESPACE
namespace Utils { class FilePath; }
namespace RemoteLinux {
namespace Ui { class SshKeyCreationDialog; }
class SshKeyCreationDialog : public QDialog
{
Q_OBJECT
@@ -51,7 +56,12 @@ private:
void showError(const QString &details);
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

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>