SshDeviceWizard: Simplify the implementation

Change-Id: Iaa8c06e5bdea210c47c7672e9399729df3139020
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-07-25 11:36:16 +02:00
parent ef005dd56e
commit 70b59e7400

View File

@@ -30,8 +30,8 @@ namespace RemoteLinux {
class SetupPage : public QWizardPage class SetupPage : public QWizardPage
{ {
public: public:
explicit SetupPage(QWidget *parent = nullptr) explicit SetupPage(const ProjectExplorer::IDevicePtr &device)
: QWizardPage(parent) : m_device(device)
{ {
setTitle(Tr::tr("Connection")); setTitle(Tr::tr("Connection"));
setWindowTitle(Tr::tr("WizardPage")); setWindowTitle(Tr::tr("WizardPage"));
@@ -62,8 +62,6 @@ public:
connect(m_userNameLineEdit, &QLineEdit::textChanged, this, &QWizardPage::completeChanged); connect(m_userNameLineEdit, &QLineEdit::textChanged, this, &QWizardPage::completeChanged);
} }
void setDevice(const ProjectExplorer::IDevicePtr &device) { m_device = device; }
private: private:
void initializePage() final { void initializePage() final {
m_nameLineEdit->setText(m_device->displayName()); m_nameLineEdit->setText(m_device->displayName());
@@ -73,13 +71,12 @@ private:
m_userNameLineEdit->setText(m_device->sshParameters().userName()); m_userNameLineEdit->setText(m_device->sshParameters().userName());
} }
bool isComplete() const final { bool isComplete() const final {
return !configurationName().isEmpty() return !m_nameLineEdit->text().trimmed().isEmpty()
&& !m_hostNameLineEdit->text().trimmed().isEmpty() && !m_hostNameLineEdit->text().trimmed().isEmpty()
&& !m_userNameLineEdit->text().trimmed().isEmpty(); && !m_userNameLineEdit->text().trimmed().isEmpty();
} }
bool validatePage() final { bool validatePage() final {
m_device->setDisplayName(configurationName()); m_device->setDisplayName(m_nameLineEdit->text().trimmed());
SshParameters sshParams = m_device->sshParameters(); SshParameters sshParams = m_device->sshParameters();
sshParams.setHost(m_hostNameLineEdit->text().trimmed()); sshParams.setHost(m_hostNameLineEdit->text().trimmed());
sshParams.setUserName(m_userNameLineEdit->text().trimmed()); sshParams.setUserName(m_userNameLineEdit->text().trimmed());
@@ -88,8 +85,6 @@ private:
return true; return true;
} }
QString configurationName() const { return m_nameLineEdit->text().trimmed(); }
FancyLineEdit *m_nameLineEdit; FancyLineEdit *m_nameLineEdit;
FancyLineEdit *m_hostNameLineEdit; FancyLineEdit *m_hostNameLineEdit;
QSpinBox *m_sshPortSpinBox; QSpinBox *m_sshPortSpinBox;
@@ -100,19 +95,17 @@ private:
class KeyDeploymentPage : public QWizardPage class KeyDeploymentPage : public QWizardPage
{ {
public: public:
explicit KeyDeploymentPage(QWidget *parent = nullptr) explicit KeyDeploymentPage(const ProjectExplorer::IDevicePtr &device)
: QWizardPage(parent) : m_device(device)
{ {
setTitle(Tr::tr("Key Deployment")); setTitle(Tr::tr("Key Deployment"));
setSubTitle(" "); setSubTitle(" ");
const QString info = Tr::tr("We recommend that you log into your device using public key " const QString info = Tr::tr(
"authentication.\n" "We recommend that you log into your device using public key authentication.\n"
"If your device is already set up for this, you do not have to do " "If your device is already set up for this, you do not have to do anything here.\n"
"anything here.\n"
"Otherwise, please deploy the public key for the private key " "Otherwise, please deploy the public key for the private key "
"with which to connect in the future.\n" "with which to connect in the future.\n"
"If you do not have a private key yet, you can also " "If you do not have a private key yet, you can also create one here.");
"create one here.");
m_keyFileChooser.setExpectedKind(PathChooser::File); m_keyFileChooser.setExpectedKind(PathChooser::File);
m_keyFileChooser.setHistoryCompleter("Ssh.KeyFile.History"); m_keyFileChooser.setHistoryCompleter("Ssh.KeyFile.History");
m_keyFileChooser.setPromptDialogTitle(Tr::tr("Choose a Private Key File")); m_keyFileChooser.setPromptDialogTitle(Tr::tr("Choose a Private Key File"));
@@ -154,8 +147,6 @@ public:
} }
} }
void setDevice(const ProjectExplorer::IDevicePtr &device) { m_device = device; }
private: private:
void initializePage() final { void initializePage() final {
if (!m_device->sshParameters().privateKeyFile.isEmpty()) if (!m_device->sshParameters().privateKeyFile.isEmpty())
@@ -175,7 +166,6 @@ private:
} }
return true; return true;
} }
FilePaths defaultKeys() const { FilePaths defaultKeys() const {
const FilePath baseDir = FileUtils::homePath() / ".ssh"; const FilePath baseDir = FileUtils::homePath() / ".ssh";
return {baseDir / "id_rsa", baseDir / "id_ecdsa", baseDir / "id_ed25519"}; return {baseDir / "id_rsa", baseDir / "id_ecdsa", baseDir / "id_ed25519"};
@@ -189,23 +179,17 @@ private:
class FinalPage final : public QWizardPage class FinalPage final : public QWizardPage
{ {
public: public:
FinalPage(QWidget *parent = nullptr) FinalPage()
: QWizardPage(parent)
{ {
setTitle(Tr::tr("Summary")); setTitle(Tr::tr("Summary"));
setSubTitle(QLatin1String(" ")); // For Qt bug (background color) setSubTitle(QLatin1String(" ")); // For Qt bug (background color)
m_infoLabel.setWordWrap(true); auto infoLabel = new QLabel(Tr::tr("The new device configuration will now be created.\n"
auto const layout = new QVBoxLayout(this);
layout->addWidget(&m_infoLabel);
}
private:
void initializePage() final {
m_infoLabel.setText(Tr::tr("The new device configuration will now be created.\n"
"In addition, device connectivity will be tested.")); "In addition, device connectivity will be tested."));
infoLabel->setWordWrap(true);
auto layout = new QVBoxLayout(this);
layout->addWidget(infoLabel);
setCommitPage(true);
} }
QLabel m_infoLabel;
}; };
SshDeviceWizard::SshDeviceWizard(const QString &title, const ProjectExplorer::IDevicePtr &device) SshDeviceWizard::SshDeviceWizard(const QString &title, const ProjectExplorer::IDevicePtr &device)
@@ -213,17 +197,9 @@ SshDeviceWizard::SshDeviceWizard(const QString &title, const ProjectExplorer::ID
{ {
setWindowTitle(title); setWindowTitle(title);
auto setupPage = new SetupPage; addPage(new SetupPage(device));
auto keyDeploymentPage = new KeyDeploymentPage; addPage(new KeyDeploymentPage(device));
auto finalPage = new FinalPage; addPage(new FinalPage);
addPage(setupPage);
addPage(keyDeploymentPage);
addPage(finalPage);
finalPage->setCommitPage(true);
setupPage->setDevice(device);
keyDeploymentPage->setDevice(device);
} }
} // namespace RemoteLinux } // namespace RemoteLinux