RemoteLinux: Make generic wizard reusable

Reuse it in QnxPlugin.

Change-Id: Ie60e2829dffa90a4097ef2a0cf1ab19220c2631f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-07-21 00:21:07 +02:00
parent 5a3dc42485
commit 661f89be41
7 changed files with 36 additions and 97 deletions

View File

@@ -112,7 +112,7 @@ void IDeviceFactory::setCombinedIcon(const FilePath &small, const FilePath &larg
Icon({{large, Theme::IconsBaseColor}})}); Icon({{large, Theme::IconsBaseColor}})});
} }
void IDeviceFactory::setCreator(const std::function<IDevice::Ptr ()> &creator) void IDeviceFactory::setCreator(const std::function<IDevice::Ptr()> &creator)
{ {
QTC_ASSERT(creator, return); QTC_ASSERT(creator, return);
m_creator = creator; m_creator = creator;

View File

@@ -12,7 +12,7 @@
#include <projectexplorer/devicesupport/sshparameters.h> #include <projectexplorer/devicesupport/sshparameters.h>
#include <remotelinux/genericlinuxdeviceconfigurationwizardpages.h> #include <remotelinux/genericlinuxdeviceconfigurationwizard.h>
#include <remotelinux/remotelinuxsignaloperation.h> #include <remotelinux/remotelinuxsignaloperation.h>
#include <remotelinux/linuxdevice.h> #include <remotelinux/linuxdevice.h>
@@ -86,36 +86,6 @@ public:
DeviceTester *createDeviceTester() const final { return new QnxDeviceTester; } DeviceTester *createDeviceTester() const final { return new QnxDeviceTester; }
}; };
class QnxDeviceWizard : public Wizard
{
public:
QnxDeviceWizard() : Wizard(Core::ICore::dialogParent())
{
setWindowTitle(Tr::tr("New QNX Device Configuration Setup"));
addPage(&m_setupPage);
addPage(&m_keyDeploymentPage);
addPage(&m_finalPage);
m_finalPage.setCommitPage(true);
m_device.reset(new QnxDevice);
m_setupPage.setDevice(m_device);
m_keyDeploymentPage.setDevice(m_device);
}
IDevice::Ptr device() const { return m_device; }
private:
GenericLinuxDeviceConfigurationWizardSetupPage m_setupPage;
GenericLinuxDeviceConfigurationWizardKeyDeploymentPage m_keyDeploymentPage;
GenericLinuxDeviceConfigurationWizardFinalPage m_finalPage;
LinuxDevice::Ptr m_device;
};
// Factory
QnxDeviceFactory::QnxDeviceFactory() : IDeviceFactory(Constants::QNX_QNX_OS_TYPE) QnxDeviceFactory::QnxDeviceFactory() : IDeviceFactory(Constants::QNX_QNX_OS_TYPE)
{ {
setDisplayName(Tr::tr("QNX Device")); setDisplayName(Tr::tr("QNX Device"));
@@ -123,11 +93,13 @@ QnxDeviceFactory::QnxDeviceFactory() : IDeviceFactory(Constants::QNX_QNX_OS_TYPE
":/qnx/images/qnxdevice.png"); ":/qnx/images/qnxdevice.png");
setQuickCreationAllowed(true); setQuickCreationAllowed(true);
setConstructionFunction([] { return IDevice::Ptr(new QnxDevice); }); setConstructionFunction([] { return IDevice::Ptr(new QnxDevice); });
setCreator([] { setCreator([]() -> IDevice::Ptr {
QnxDeviceWizard wizard; const IDevice::Ptr device = IDevice::Ptr(new QnxDevice);
GenericLinuxDeviceConfigurationWizard wizard(
Tr::tr("New QNX Device Configuration Setup"), device);
if (wizard.exec() != QDialog::Accepted) if (wizard.exec() != QDialog::Accepted)
return IDevice::Ptr(); return {};
return wizard.device(); return device;
}); });
} }

View File

@@ -4,57 +4,28 @@
#include "genericlinuxdeviceconfigurationwizard.h" #include "genericlinuxdeviceconfigurationwizard.h"
#include "genericlinuxdeviceconfigurationwizardpages.h" #include "genericlinuxdeviceconfigurationwizardpages.h"
#include "linuxdevice.h"
#include "remotelinux_constants.h"
#include "remotelinuxtr.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/devicesupport/sshparameters.h>
#include <utils/fileutils.h>
using namespace ProjectExplorer;
namespace RemoteLinux { namespace RemoteLinux {
namespace Internal {
class GenericLinuxDeviceConfigurationWizardPrivate GenericLinuxDeviceConfigurationWizard::GenericLinuxDeviceConfigurationWizard(
{ const QString &title, const ProjectExplorer::IDevicePtr &device)
public:
GenericLinuxDeviceConfigurationWizardSetupPage setupPage;
GenericLinuxDeviceConfigurationWizardKeyDeploymentPage keyDeploymentPage;
GenericLinuxDeviceConfigurationWizardFinalPage finalPage;
LinuxDevice::Ptr device;
};
} // namespace Internal
GenericLinuxDeviceConfigurationWizard::GenericLinuxDeviceConfigurationWizard()
: Utils::Wizard(Core::ICore::dialogParent()) : Utils::Wizard(Core::ICore::dialogParent())
, d(new Internal::GenericLinuxDeviceConfigurationWizardPrivate)
{ {
setWindowTitle(Tr::tr("New Remote Linux Device Configuration Setup")); setWindowTitle(title);
addPage(&d->setupPage);
addPage(&d->keyDeploymentPage);
addPage(&d->finalPage);
d->finalPage.setCommitPage(true);
d->device = LinuxDevice::create(); auto setupPage = new GenericLinuxDeviceConfigurationWizardSetupPage;
auto keyDeploymentPage = new GenericLinuxDeviceConfigurationWizardKeyDeploymentPage;
auto finalPage = new GenericLinuxDeviceConfigurationWizardFinalPage;
d->setupPage.setDevice(d->device); addPage(setupPage);
d->keyDeploymentPage.setDevice(d->device); addPage(keyDeploymentPage);
} addPage(finalPage);
GenericLinuxDeviceConfigurationWizard::~GenericLinuxDeviceConfigurationWizard() finalPage->setCommitPage(true);
{ setupPage->setDevice(device);
delete d; keyDeploymentPage->setDevice(device);
}
IDevice::Ptr GenericLinuxDeviceConfigurationWizard::device()
{
return d->device;
} }
} // namespace RemoteLinux } // namespace RemoteLinux

View File

@@ -9,20 +9,14 @@
#include <utils/wizard.h> #include <utils/wizard.h>
namespace RemoteLinux { namespace RemoteLinux {
namespace Internal { class GenericLinuxDeviceConfigurationWizardPrivate; }
class REMOTELINUX_EXPORT GenericLinuxDeviceConfigurationWizard : public Utils::Wizard class REMOTELINUX_EXPORT GenericLinuxDeviceConfigurationWizard : public Utils::Wizard
{ {
Q_OBJECT Q_OBJECT
public: public:
GenericLinuxDeviceConfigurationWizard(); GenericLinuxDeviceConfigurationWizard(const QString &title,
~GenericLinuxDeviceConfigurationWizard() override; const ProjectExplorer::IDevicePtr &device);
ProjectExplorer::IDevicePtr device();
private:
Internal::GenericLinuxDeviceConfigurationWizardPrivate * const d;
}; };
} // namespace RemoteLinux } // namespace RemoteLinux

View File

@@ -35,7 +35,7 @@ public:
QSpinBox *sshPortSpinBox; QSpinBox *sshPortSpinBox;
FancyLineEdit *userNameLineEdit; FancyLineEdit *userNameLineEdit;
LinuxDevice::Ptr device; IDevicePtr device;
}; };
class GenericLinuxDeviceConfigurationWizardFinalPagePrivate class GenericLinuxDeviceConfigurationWizardFinalPagePrivate
@@ -116,7 +116,8 @@ QString GenericLinuxDeviceConfigurationWizardSetupPage::configurationName() cons
return d->nameLineEdit->text().trimmed(); return d->nameLineEdit->text().trimmed();
} }
void GenericLinuxDeviceConfigurationWizardSetupPage::setDevice(const LinuxDevice::Ptr &device) void GenericLinuxDeviceConfigurationWizardSetupPage::setDevice(
const ProjectExplorer::IDevicePtr &device)
{ {
d->device = device; d->device = device;
} }
@@ -158,7 +159,7 @@ struct GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::Private
PathChooser keyFileChooser; PathChooser keyFileChooser;
QLabel iconLabel; QLabel iconLabel;
LinuxDevice::Ptr device; IDevicePtr device;
}; };
GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::GenericLinuxDeviceConfigurationWizardKeyDeploymentPage(QWidget *parent) GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::GenericLinuxDeviceConfigurationWizardKeyDeploymentPage(QWidget *parent)
@@ -214,7 +215,8 @@ GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::~GenericLinuxDeviceConfi
delete d; delete d;
} }
void GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::setDevice(const LinuxDevice::Ptr &device) void GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::setDevice(
const ProjectExplorer::IDevicePtr &device)
{ {
d->device = device; d->device = device;
} }

View File

@@ -24,7 +24,7 @@ public:
explicit GenericLinuxDeviceConfigurationWizardSetupPage(QWidget *parent = nullptr); explicit GenericLinuxDeviceConfigurationWizardSetupPage(QWidget *parent = nullptr);
~GenericLinuxDeviceConfigurationWizardSetupPage() override; ~GenericLinuxDeviceConfigurationWizardSetupPage() override;
void setDevice(const LinuxDevice::Ptr &device); void setDevice(const ProjectExplorer::IDevicePtr &device);
private: private:
void initializePage() override; void initializePage() override;
@@ -44,7 +44,7 @@ public:
explicit GenericLinuxDeviceConfigurationWizardKeyDeploymentPage(QWidget *parent = nullptr); explicit GenericLinuxDeviceConfigurationWizardKeyDeploymentPage(QWidget *parent = nullptr);
~GenericLinuxDeviceConfigurationWizardKeyDeploymentPage() override; ~GenericLinuxDeviceConfigurationWizardKeyDeploymentPage() override;
void setDevice(const LinuxDevice::Ptr &device); void setDevice(const ProjectExplorer::IDevicePtr &device);
private: private:
void initializePage() override; void initializePage() override;

View File

@@ -1475,8 +1475,6 @@ void LinuxDevice::checkOsType()
namespace Internal { namespace Internal {
// Factory
LinuxDeviceFactory::LinuxDeviceFactory() LinuxDeviceFactory::LinuxDeviceFactory()
: IDeviceFactory(Constants::GenericLinuxOsType) : IDeviceFactory(Constants::GenericLinuxOsType)
{ {
@@ -1484,11 +1482,13 @@ LinuxDeviceFactory::LinuxDeviceFactory()
setIcon(QIcon()); setIcon(QIcon());
setConstructionFunction(&LinuxDevice::create); setConstructionFunction(&LinuxDevice::create);
setQuickCreationAllowed(true); setQuickCreationAllowed(true);
setCreator([] { setCreator([]() -> IDevice::Ptr {
GenericLinuxDeviceConfigurationWizard wizard; const IDevice::Ptr device = LinuxDevice::create();
GenericLinuxDeviceConfigurationWizard wizard(
Tr::tr("New Remote Linux Device Configuration Setup"), device);
if (wizard.exec() != QDialog::Accepted) if (wizard.exec() != QDialog::Accepted)
return IDevice::Ptr(); return {};
return wizard.device(); return device;
}); });
} }