Device Support: Move some functions from IDeviceFactory to IDevice.

Now that we have a polymorphic device class, we don't need to
attach all the virtual functions to the factory anymore.
In addition, the isUserEditable() function is gone, because it is
no longer needed in the presence of device-specific widgets.

Change-Id: Ie8f0be95653cb83e1618885b08cdd2aacf5dda59
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
Christian Kandeler
2012-04-06 18:28:16 +02:00
parent 8bdbbab157
commit e2d8a9600e
17 changed files with 238 additions and 225 deletions

View File

@@ -31,8 +31,22 @@
**************************************************************************/
#include "maddedevice.h"
#include "maddedevicetester.h"
#include "maemoconstants.h"
#include <remotelinux/linuxdevicetestdialog.h>
#include <remotelinux/publickeydeploymentdialog.h>
#include <remotelinux/remotelinuxprocessesdialog.h>
#include <remotelinux/remotelinuxprocesslist.h>
#include <remotelinux/remotelinux_constants.h>
#include <utils/qtcassert.h>
using namespace RemoteLinux;
namespace Madde {
namespace Internal {
const char MaddeDeviceTestActionId[] = "Madde.DeviceTestAction";
const char MaddeRemoteProcessesActionId[] = "Madde.RemoteProcessesAction";
MaddeDevice::Ptr MaddeDevice::create()
{
@@ -64,5 +78,54 @@ ProjectExplorer::IDevice::Ptr MaddeDevice::clone() const
return Ptr(new MaddeDevice(*this));
}
QString MaddeDevice::displayType() const
{
return maddeDisplayType(type());
}
QStringList MaddeDevice::actionIds() const
{
return QStringList() << QLatin1String(MaddeDeviceTestActionId)
<< QLatin1String(Constants::GenericDeployKeyToDeviceActionId)
<< QLatin1String(MaddeRemoteProcessesActionId);
}
QString MaddeDevice::displayNameForActionId(const QString &actionId) const
{
QTC_ASSERT(actionIds().contains(actionId), return QString());
if (actionId == QLatin1String(MaddeDeviceTestActionId))
return tr("Test");
if (actionId == QLatin1String(MaddeRemoteProcessesActionId))
return tr("Remote Processes...");
if (actionId == QLatin1String(Constants::GenericDeployKeyToDeviceActionId))
return tr("Deploy Public Key...");
return QString(); // Can't happen.
}
QDialog *MaddeDevice::createAction(const QString &actionId, QWidget *parent) const
{
QTC_ASSERT(actionIds().contains(actionId), return 0);
const LinuxDeviceConfiguration::ConstPtr device
= sharedFromThis().staticCast<const LinuxDeviceConfiguration>();
if (actionId == QLatin1String(MaddeDeviceTestActionId))
return new LinuxDeviceTestDialog(device, new MaddeDeviceTester, parent);
if (actionId == QLatin1String(MaddeRemoteProcessesActionId))
return new RemoteLinuxProcessesDialog(new GenericRemoteLinuxProcessList(device), parent);
if (actionId == QLatin1String(Constants::GenericDeployKeyToDeviceActionId))
return PublicKeyDeploymentDialog::createDialog(device, parent);
return 0; // Can't happen.
}
QString MaddeDevice::maddeDisplayType(const QString &type)
{
if (type == QLatin1String(Maemo5OsType))
return tr("Maemo5/Fremantle");
if (type == QLatin1String(HarmattanOsType))
return tr("MeeGo 1.2 Harmattan");
return tr("Other MeeGo OS");
}
} // namespace Internal
} // namespace Madde

View File

@@ -34,11 +34,14 @@
#include <remotelinux/linuxdeviceconfiguration.h>
#include <QCoreApplication>
namespace Madde {
namespace Internal {
class MaddeDevice : public RemoteLinux::LinuxDeviceConfiguration
{
Q_DECLARE_TR_FUNCTIONS(MaddeDevice)
public:
typedef QSharedPointer<MaddeDevice> Ptr;
typedef QSharedPointer<const MaddeDevice> ConstPtr;
@@ -47,7 +50,12 @@ public:
static Ptr create(const QString &name, const QString &type, MachineType machineType,
Origin origin = ManuallyAdded, const QString &fingerprint = QString());
QString displayType() const;
QStringList actionIds() const;
QString displayNameForActionId(const QString &actionId) const;
QDialog *createAction(const QString &actionId, QWidget *parent) const;
ProjectExplorer::IDevice::Ptr clone() const;
static QString maddeDisplayType(const QString &type);
private:
MaddeDevice();

View File

@@ -32,16 +32,9 @@
#include "maddedeviceconfigurationfactory.h"
#include "maddedevice.h"
#include "maddedevicetester.h"
#include "maemoconstants.h"
#include "maemodeviceconfigwizard.h"
#include <remotelinux/linuxdevicetestdialog.h>
#include <remotelinux/publickeydeploymentdialog.h>
#include <remotelinux/remotelinuxprocessesdialog.h>
#include <remotelinux/remotelinuxprocesslist.h>
#include <remotelinux/remotelinux_constants.h>
#include <remotelinux/genericlinuxdeviceconfigurationwidget.h>
#include <utils/qtcassert.h>
using namespace ProjectExplorer;
@@ -49,10 +42,6 @@ using namespace RemoteLinux;
namespace Madde {
namespace Internal {
namespace {
const char MaddeDeviceTestActionId[] = "Madde.DeviceTestAction";
const char MaddeRemoteProcessesActionId[] = "Madde.RemoteProcessesAction";
} // anonymous namespace
MaddeDeviceConfigurationFactory::MaddeDeviceConfigurationFactory(QObject *parent)
: IDeviceFactory(parent)
@@ -69,13 +58,6 @@ IDeviceWizard *MaddeDeviceConfigurationFactory::createWizard(QWidget *parent) co
return new MaemoDeviceConfigWizard(parent);
}
IDeviceWidget *MaddeDeviceConfigurationFactory::createWidget(const IDevice::Ptr &device,
QWidget *parent) const
{
return new GenericLinuxDeviceConfigurationWidget(device.staticCast<LinuxDeviceConfiguration>(),
parent);
}
IDevice::Ptr MaddeDeviceConfigurationFactory::loadDevice(const QVariantMap &map) const
{
QTC_ASSERT(supportsDeviceType(IDevice::typeFromMap(map)), return MaddeDevice::Ptr());
@@ -90,51 +72,5 @@ bool MaddeDeviceConfigurationFactory::supportsDeviceType(const QString &type) co
|| type == QLatin1String(MeeGoOsType);
}
QString MaddeDeviceConfigurationFactory::displayNameForDeviceType(const QString &deviceType) const
{
QTC_ASSERT(supportsDeviceType(deviceType), return QString());
if (deviceType == QLatin1String(Maemo5OsType))
return tr("Maemo5/Fremantle");
if (deviceType == QLatin1String(HarmattanOsType))
return tr("MeeGo 1.2 Harmattan");
return tr("Other MeeGo OS");
}
QStringList MaddeDeviceConfigurationFactory::supportedDeviceActionIds() const
{
return QStringList() << QLatin1String(MaddeDeviceTestActionId)
<< QLatin1String(Constants::GenericDeployKeyToDeviceActionId)
<< QLatin1String(MaddeRemoteProcessesActionId);
}
QString MaddeDeviceConfigurationFactory::displayNameForActionId(const QString &actionId) const
{
Q_ASSERT(supportedDeviceActionIds().contains(actionId));
if (actionId == QLatin1String(MaddeDeviceTestActionId))
return tr("Test");
if (actionId == QLatin1String(MaddeRemoteProcessesActionId))
return tr("Remote Processes...");
if (actionId == QLatin1String(Constants::GenericDeployKeyToDeviceActionId))
return tr("Deploy Public Key...");
return QString(); // Can't happen.
}
QDialog *MaddeDeviceConfigurationFactory::createDeviceAction(const QString &actionId,
const IDevice::ConstPtr &device, QWidget *parent) const
{
Q_ASSERT(supportedDeviceActionIds().contains(actionId));
const LinuxDeviceConfiguration::ConstPtr lDevice
= device.staticCast<const LinuxDeviceConfiguration>();
if (actionId == QLatin1String(MaddeDeviceTestActionId))
return new LinuxDeviceTestDialog(lDevice, new MaddeDeviceTester, parent);
if (actionId == QLatin1String(MaddeRemoteProcessesActionId))
return new RemoteLinuxProcessesDialog(new GenericRemoteLinuxProcessList(lDevice), parent);
if (actionId == QLatin1String(Constants::GenericDeployKeyToDeviceActionId))
return PublicKeyDeploymentDialog::createDialog(lDevice, parent);
return 0; // Can't happen.
}
} // namespace Internal
} // namespace Madde

View File

@@ -45,15 +45,8 @@ public:
QString displayName() const;
ProjectExplorer::IDeviceWizard *createWizard(QWidget *parent) const;
ProjectExplorer::IDeviceWidget *createWidget(
const ProjectExplorer::IDevice::Ptr &device, QWidget *parent = 0) const;
ProjectExplorer::IDevice::Ptr loadDevice(const QVariantMap &map) const;
bool supportsDeviceType(const QString &type) const;
QString displayNameForDeviceType(const QString &deviceType) const;
QStringList supportedDeviceActionIds() const;
QString displayNameForActionId(const QString &actionId) const;
QDialog *createDeviceAction(const QString &actionId,
const ProjectExplorer::IDevice::ConstPtr &device, QWidget *parent) const;
};
} // namespace Internal

View File

@@ -41,7 +41,6 @@
#include "maemoconstants.h"
#include "maemoglobal.h"
#include <projectexplorer/devicesupport/devicemanager.h>
#include <remotelinux/genericlinuxdeviceconfigurationwizardpages.h>
#include <remotelinux/linuxdevicetestdialog.h>
#include <remotelinux/sshkeydeployer.h>
@@ -106,11 +105,11 @@ public:
setTitle(tr("General Information"));
setSubTitle(QLatin1String(" ")); // For Qt bug (background color)
m_ui->osTypeComboBox->addItem(DeviceManager::displayNameForDeviceType(QLatin1String(Maemo5OsType)),
m_ui->osTypeComboBox->addItem(MaddeDevice::maddeDisplayType(QLatin1String(Maemo5OsType)),
QLatin1String(Maemo5OsType));
m_ui->osTypeComboBox->addItem(DeviceManager::displayNameForDeviceType(QLatin1String(HarmattanOsType)),
m_ui->osTypeComboBox->addItem(MaddeDevice::maddeDisplayType(QLatin1String(HarmattanOsType)),
QLatin1String(HarmattanOsType));
m_ui->osTypeComboBox->addItem(DeviceManager::displayNameForDeviceType(QLatin1String(MeeGoOsType)),
m_ui->osTypeComboBox->addItem(MaddeDevice::maddeDisplayType(QLatin1String(MeeGoOsType)),
QLatin1String(MeeGoOsType));
QButtonGroup *buttonGroup = new QButtonGroup(this);

View File

@@ -332,13 +332,6 @@ const IDeviceFactory *DeviceManager::factoryForDeviceType(const QString &type)
return 0;
}
QString DeviceManager::displayNameForDeviceType(const QString &type)
{
if (const IDeviceFactory * const factory = factoryForDeviceType(type))
return factory->displayNameForDeviceType(type);
return tr("Unknown OS");
}
DeviceManager::DeviceManager(bool doLoad) : d(new DeviceManagerPrivate)
{
if (doLoad)
@@ -428,4 +421,25 @@ IDevice::Id DeviceManager::unusedId() const
return IDevice::invalidId();
}
IDevice::Ptr DeviceManager::fromRawPointer(IDevice *device) const
{
foreach (const IDevice::Ptr &devPtr, d->devices) {
if (devPtr == device)
return devPtr;
}
if (this == instance() && d->clonedInstance)
return d->clonedInstance->fromRawPointer(device);
qWarning("%s: Device not found.", Q_FUNC_INFO);
return IDevice::Ptr();
}
IDevice::ConstPtr DeviceManager::fromRawPointer(const IDevice *device) const
{
// The const_cast is safe, because we convert the Ptr back to a ConstPtr before returning it.
return fromRawPointer(const_cast<IDevice *>(device));
}
} // namespace ProjectExplorer

View File

@@ -50,6 +50,7 @@ class PROJECTEXPLORER_EXPORT DeviceManager : public QObject
{
Q_OBJECT
friend class Internal::DeviceSettingsWidget;
friend class IDevice;
public:
~DeviceManager();
@@ -70,7 +71,6 @@ public:
void removeDevice(int index);
static const IDeviceFactory *factoryForDeviceType(const QString &type);
static QString displayNameForDeviceType(const QString &type);
signals:
void deviceAdded(const QSharedPointer<const IDevice> &device);
@@ -100,6 +100,10 @@ private:
static void replaceInstance();
static void removeClonedInstance();
// For IDevice.
IDevice::Ptr fromRawPointer(IDevice *device) const;
IDevice::ConstPtr fromRawPointer(const IDevice *device) const;
static QString settingsFilePath();
static void copy(const DeviceManager *source, DeviceManager *target, bool deep);

View File

@@ -104,10 +104,8 @@ QVariant DeviceManagerModel::data(const QModelIndex &index, int role) const
return QVariant();
const IDevice::ConstPtr device = d->devices.at(index.row());
QString name = device->displayName();
if (d->deviceManager->defaultDevice(device->type()) == device) {
name = tr("%1 (default for %2)").arg(name,
d->deviceManager->displayNameForDeviceType(device->type()));
}
if (d->deviceManager->defaultDevice(device->type()) == device)
name = tr("%1 (default for %2)").arg(name, device->displayType());
return name;
}

View File

@@ -42,6 +42,7 @@
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/portlist.h>
#include <utils/qtcassert.h>
#include <QFileInfo>
#include <QRegExp>
@@ -115,6 +116,7 @@ DeviceSettingsWidget::~DeviceSettingsWidget()
DeviceManager::replaceInstance();
}
DeviceManager::removeClonedInstance();
delete m_configWidget;
delete m_ui;
}
@@ -181,7 +183,7 @@ void DeviceSettingsWidget::displayCurrent()
const IDevice::ConstPtr &current = currentDevice();
m_ui->defaultDeviceButton->setEnabled(
m_deviceManager->defaultDevice(current->type()) != current);
m_ui->osTypeValueLabel->setText(DeviceManager::displayNameForDeviceType(current->type()));
m_ui->osTypeValueLabel->setText(current->displayType());
m_ui->autoDetectionValueLabel->setText(current->isAutoDetected()
? tr("Yes (fingerprint is '%1')").arg(current->fingerprint()) : tr("No"));
m_nameValidator->setDisplayName(current->displayName());
@@ -234,36 +236,26 @@ void DeviceSettingsWidget::currentDeviceChanged(int index)
delete m_configWidget;
m_configWidget = 0;
m_additionalActionButtons.clear();
m_ui->generalGroupBox->setEnabled(false);
m_ui->osSpecificGroupBox->setEnabled(false);
QTC_ASSERT(index >= -1 && index < m_deviceManager->deviceCount(), return);
if (index == -1) {
m_ui->removeConfigButton->setEnabled(false);
clearDetails();
m_ui->defaultDeviceButton->setEnabled(false);
} else {
m_ui->removeConfigButton->setEnabled(true);
const IDeviceFactory * const factory = factoryForCurrentDevice();
if (factory) {
const QStringList &actionIds = factory->supportedDeviceActionIds();
foreach (const QString &actionId, actionIds) {
QPushButton * const button = new QPushButton(
factory->displayNameForActionId(actionId));
m_additionalActionButtons << button;
connect(button, SIGNAL(clicked()), m_additionalActionsMapper, SLOT(map()));
m_additionalActionsMapper->setMapping(button, actionId);
m_ui->buttonsLayout->insertWidget(m_ui->buttonsLayout->count() - 1, button);
}
if (!m_ui->osSpecificGroupBox->layout())
new QVBoxLayout(m_ui->osSpecificGroupBox);
m_configWidget = factory->createWidget(m_deviceManager->mutableDeviceAt(currentIndex()),
m_ui->osSpecificGroupBox);
if (m_configWidget) {
m_ui->osSpecificGroupBox->layout()->addWidget(m_configWidget);
m_ui->osSpecificGroupBox->setEnabled(factory->isUserEditable());
}
m_ui->generalGroupBox->setEnabled(factory->isUserEditable());
const IDevice::ConstPtr device = m_deviceManager->deviceAt(index);
foreach (const QString &actionId, device->actionIds()) {
QPushButton * const button = new QPushButton(device->displayNameForActionId(actionId));
m_additionalActionButtons << button;
connect(button, SIGNAL(clicked()), m_additionalActionsMapper, SLOT(map()));
m_additionalActionsMapper->setMapping(button, actionId);
m_ui->buttonsLayout->insertWidget(m_ui->buttonsLayout->count() - 1, button);
}
m_ui->configurationComboBox->setCurrentIndex(index);
if (!m_ui->osSpecificGroupBox->layout())
new QVBoxLayout(m_ui->osSpecificGroupBox);
m_configWidget = m_deviceManager->mutableDeviceAt(index)->createWidget();
if (m_configWidget)
m_ui->osSpecificGroupBox->layout()->addWidget(m_configWidget);
displayCurrent();
}
}
@@ -275,17 +267,11 @@ void DeviceSettingsWidget::clearDetails()
m_ui->autoDetectionValueLabel->clear();
}
const IDeviceFactory *DeviceSettingsWidget::factoryForCurrentDevice() const
{
Q_ASSERT(currentDevice());
return DeviceManager::factoryForDeviceType(currentDevice()->type());
}
void DeviceSettingsWidget::handleAdditionalActionRequest(const QString &actionId)
{
const IDeviceFactory * const factory = factoryForCurrentDevice();
Q_ASSERT(factory);
QDialog * const action = factory->createDeviceAction(actionId, currentDevice(), this);
const IDevice::ConstPtr &device = currentDevice();
QTC_ASSERT(device, return);
QDialog * const action = device->createAction(actionId, this);
if (action)
action->exec();
delete action;

View File

@@ -44,7 +44,6 @@ QT_END_NAMESPACE
namespace ProjectExplorer {
class IDevice;
class DeviceManager;
class IDeviceFactory;
class IDeviceWidget;
namespace Internal {
@@ -77,7 +76,6 @@ private:
void clearDetails();
QString parseTestOutput();
void fillInValues();
const IDeviceFactory *factoryForCurrentDevice() const;
Ui::DeviceSettingsWidget *m_ui;
DeviceManager * const m_deviceManager;

View File

@@ -31,6 +31,8 @@
**************************************************************************/
#include "idevice.h"
#include "devicemanager.h"
#include <utils/qtcassert.h>
#include <QString>
@@ -91,7 +93,37 @@
*/
/*!
* \fn ProjectExplorer::IDevice::Ptr ProjectExploer::IDevice::clone() const
* \fn QString ProjectExplorer::IDevice::displayType() const
* \brief Prints a representation of the device's type suitable for displaying to a user.
*/
/*!
* \fn ProjectExplorer::IDeviceWidget *ProjectExplorer::IDevice::createWidget() const
* \brief Creates a widget that displays device information not part of the IDevice base class.
* The widget can also be used to let the user change these attributes.
*/
/*!
* \fn QStringList ProjectExplorer::IDevice::actionIds() const
* \brief Returns a list of ids representing actions that can be run on this device.
* These actions will be available in the "Devices" options page.
*/
/*!
* \fn QString ProjectExplorer::IDevice::displayNameForActionId(const QString &actionId) const
* \brief A human-readable string for the given id. Will be displayed on a button which,
* when clicked, starts the respective action.
*/
/*!
* \fn QDialog *ProjectExplorer::IDevice::createAction(const QString &actionId) const
* \brief Produces a dialog implementing the respective action. The dialog is supposed to be
* modal, so implementers must make sure to make whatever it does interruptible as
* to not needlessly block the UI.
*/
/*!
* \fn ProjectExplorer::IDevice::Ptr ProjectExplorer::IDevice::clone() const
* \brief Creates an identical copy of a device object.
*/
@@ -218,4 +250,14 @@ QVariantMap IDevice::toMap() const
return map;
}
IDevice::Ptr IDevice::sharedFromThis()
{
return DeviceManager::instance()->fromRawPointer(this);
}
IDevice::ConstPtr IDevice::sharedFromThis() const
{
return DeviceManager::instance()->fromRawPointer(this);
}
} // namespace ProjectExplorer

View File

@@ -35,10 +35,17 @@
#include <projectexplorer/projectexplorer_export.h>
#include <QSharedPointer>
#include <QStringList>
#include <QVariantMap>
QT_BEGIN_NAMESPACE
class QDialog;
class QWidget;
QT_END_NAMESPACE
namespace ProjectExplorer {
namespace Internal { class IDevicePrivate; }
class IDeviceWidget;
// See cpp file for documentation.
class PROJECTEXPLORER_EXPORT IDevice
@@ -62,6 +69,11 @@ public:
QString fingerprint() const;
Id internalId() const;
virtual QString displayType() const = 0;
virtual IDeviceWidget *createWidget() = 0;
virtual QStringList actionIds() const = 0;
virtual QString displayNameForActionId(const QString &actionId) const = 0;
virtual QDialog *createAction(const QString &actionId, QWidget *parent = 0) const = 0;
virtual void fromMap(const QVariantMap &map);
virtual Ptr clone() const = 0;
@@ -74,6 +86,9 @@ protected:
IDevice(const QString &type, Origin origin, const QString fingerprint = QString());
IDevice(const IDevice &other);
Ptr sharedFromThis();
ConstPtr sharedFromThis() const;
virtual QVariantMap toMap() const;
private:

View File

@@ -36,16 +36,13 @@
#include <projectexplorer/projectexplorer_export.h>
#include <QObject>
#include <QStringList>
#include <QVariantMap>
QT_BEGIN_NAMESPACE
class QDialog;
class QWidget;
QT_END_NAMESPACE
namespace ProjectExplorer {
class IDeviceWidget;
class IDeviceWizard;
/*!
@@ -77,49 +74,11 @@ public:
*/
virtual IDevice::Ptr loadDevice(const QVariantMap &map) const = 0;
/*!
A widget that can configure the device this factory supports.
*/
virtual IDeviceWidget *createWidget(const IDevice::Ptr &device, QWidget *parent = 0) const = 0;
/*!
Returns true iff this factory supports the given device type.
*/
virtual bool supportsDeviceType(const QString &type) const = 0;
/*!
Returns a human-readable string for the given device type, if this factory supports that type.
*/
virtual QString displayNameForDeviceType(const QString &type) const = 0;
/*!
Returns a list of ids representing actions that can be run on devices
that this factory supports. These actions will be available in the "Devices"
options page.
*/
virtual QStringList supportedDeviceActionIds() const = 0;
/*!
A human-readable string for the given id. Will be displayed on a button which, when clicked,
starts the respective action.
*/
virtual QString displayNameForActionId(const QString &actionId) const = 0;
/*!
True iff the user should be allowed to edit the devices created by this
factory. Returns true by default. Override if your factory creates fixed configurations
for which later editing makes no sense.
*/
virtual bool isUserEditable() const { return true; }
/*!
Produces a dialog implementing the respective action. The dialog is supposed to be
modal, so implementers must make sure to make it interruptible as to not needlessly
block the UI.
*/
virtual QDialog *createDeviceAction(const QString &actionId, const IDevice::ConstPtr &device,
QWidget *parent = 0) const = 0;
protected:
IDeviceFactory(QObject *parent) : QObject(parent) { }
};

View File

@@ -32,12 +32,7 @@
#include "genericlinuxdeviceconfigurationfactory.h"
#include "genericlinuxdeviceconfigurationwizard.h"
#include "genericlinuxdeviceconfigurationwidget.h"
#include "linuxdeviceconfiguration.h"
#include "linuxdevicetestdialog.h"
#include "publickeydeploymentdialog.h"
#include "remotelinuxprocessesdialog.h"
#include "remotelinuxprocesslist.h"
#include "remotelinux_constants.h"
#include <utils/qtcassert.h>
@@ -61,13 +56,6 @@ IDeviceWizard *GenericLinuxDeviceConfigurationFactory::createWizard(QWidget *par
return new GenericLinuxDeviceConfigurationWizard(parent);
}
IDeviceWidget *GenericLinuxDeviceConfigurationFactory::createWidget(const IDevice::Ptr &device,
QWidget *parent) const
{
return new GenericLinuxDeviceConfigurationWidget(device.staticCast<LinuxDeviceConfiguration>(),
parent);
}
IDevice::Ptr GenericLinuxDeviceConfigurationFactory::loadDevice(const QVariantMap &map) const
{
QTC_ASSERT(supportsDeviceType(IDevice::typeFromMap(map)),
@@ -82,46 +70,4 @@ bool GenericLinuxDeviceConfigurationFactory::supportsDeviceType(const QString &d
return deviceType == QLatin1String(Constants::GenericLinuxOsType);
}
QString GenericLinuxDeviceConfigurationFactory::displayNameForDeviceType(const QString &deviceType) const
{
QTC_ASSERT(supportsDeviceType(deviceType), return QString());
return tr("Generic Linux");
}
QStringList GenericLinuxDeviceConfigurationFactory::supportedDeviceActionIds() const
{
return QStringList() << QLatin1String(Constants::GenericTestDeviceActionId)
<< QLatin1String(Constants::GenericDeployKeyToDeviceActionId)
<< QLatin1String(Constants::GenericRemoteProcessesActionId);
}
QString GenericLinuxDeviceConfigurationFactory::displayNameForActionId(const QString &actionId) const
{
QTC_ASSERT(supportedDeviceActionIds().contains(actionId), return QString());
if (actionId == QLatin1String(Constants::GenericTestDeviceActionId))
return tr("Test");
if (actionId == QLatin1String(Constants::GenericRemoteProcessesActionId))
return tr("Remote Processes...");
if (actionId == QLatin1String(Constants::GenericDeployKeyToDeviceActionId))
return tr("Deploy Public Key...");
return QString(); // Can't happen.
}
QDialog *GenericLinuxDeviceConfigurationFactory::createDeviceAction(const QString &actionId,
const IDevice::ConstPtr &device, QWidget *parent) const
{
QTC_ASSERT(supportedDeviceActionIds().contains(actionId), return 0);
const LinuxDeviceConfiguration::ConstPtr lDevice
= device.staticCast<const LinuxDeviceConfiguration>();
if (actionId == QLatin1String(Constants::GenericTestDeviceActionId))
return new LinuxDeviceTestDialog(lDevice, new GenericLinuxDeviceTester, parent);
if (actionId == QLatin1String(Constants::GenericRemoteProcessesActionId))
return new RemoteLinuxProcessesDialog(new GenericRemoteLinuxProcessList(lDevice, parent));
if (actionId == QLatin1String(Constants::GenericDeployKeyToDeviceActionId))
return PublicKeyDeploymentDialog::createDialog(lDevice, parent);
return 0; // Can't happen.
}
} // namespace RemoteLinux

View File

@@ -48,15 +48,8 @@ public:
QString displayName() const;
ProjectExplorer::IDeviceWizard *createWizard(QWidget *parent) const;
ProjectExplorer::IDeviceWidget *createWidget(const ProjectExplorer::IDevice::Ptr &device,
QWidget *parent = 0) const;
ProjectExplorer::IDevice::Ptr loadDevice(const QVariantMap &map) const;
bool supportsDeviceType(const QString &deviceType) const;
QString displayNameForDeviceType(const QString &deviceType) const;
QStringList supportedDeviceActionIds() const;
QString displayNameForActionId(const QString &actionId) const;
QDialog *createDeviceAction(const QString &actionId,
const ProjectExplorer::IDevice::ConstPtr &device, QWidget *parent) const;
};
} // namespace RemoteLinux

View File

@@ -31,6 +31,11 @@
**************************************************************************/
#include "linuxdeviceconfiguration.h"
#include "genericlinuxdeviceconfigurationwidget.h"
#include "linuxdevicetestdialog.h"
#include "publickeydeploymentdialog.h"
#include "remotelinuxprocessesdialog.h"
#include "remotelinuxprocesslist.h"
#include "remotelinux_constants.h"
#include <utils/portlist.h>
@@ -84,6 +89,52 @@ LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const QString &na
return Ptr(new LinuxDeviceConfiguration(name, type, machineType, origin, fingerprint));
}
QString LinuxDeviceConfiguration::displayType() const
{
return tr("Generic Linux");
}
ProjectExplorer::IDeviceWidget *LinuxDeviceConfiguration::createWidget()
{
return new GenericLinuxDeviceConfigurationWidget(sharedFromThis()
.staticCast<LinuxDeviceConfiguration>());
}
QStringList LinuxDeviceConfiguration::actionIds() const
{
return QStringList() << QLatin1String(Constants::GenericTestDeviceActionId)
<< QLatin1String(Constants::GenericDeployKeyToDeviceActionId)
<< QLatin1String(Constants::GenericRemoteProcessesActionId);
}
QString LinuxDeviceConfiguration::displayNameForActionId(const QString &actionId) const
{
QTC_ASSERT(actionIds().contains(actionId), return QString());
if (actionId == QLatin1String(Constants::GenericTestDeviceActionId))
return tr("Test");
if (actionId == QLatin1String(Constants::GenericRemoteProcessesActionId))
return tr("Remote Processes...");
if (actionId == QLatin1String(Constants::GenericDeployKeyToDeviceActionId))
return tr("Deploy Public Key...");
return QString(); // Can't happen.
}
QDialog *LinuxDeviceConfiguration::createAction(const QString &actionId, QWidget *parent) const
{
QTC_ASSERT(actionIds().contains(actionId), return 0);
const LinuxDeviceConfiguration::ConstPtr device
= sharedFromThis().staticCast<const LinuxDeviceConfiguration>();
if (actionId == QLatin1String(Constants::GenericTestDeviceActionId))
return new LinuxDeviceTestDialog(device, new GenericLinuxDeviceTester, parent);
if (actionId == QLatin1String(Constants::GenericRemoteProcessesActionId))
return new RemoteLinuxProcessesDialog(new GenericRemoteLinuxProcessList(device, parent));
if (actionId == QLatin1String(Constants::GenericDeployKeyToDeviceActionId))
return PublicKeyDeploymentDialog::createDialog(device, parent);
return 0; // Can't happen.
}
LinuxDeviceConfiguration::LinuxDeviceConfiguration() : d(new LinuxDeviceConfigurationPrivate)
{
}

View File

@@ -36,6 +36,8 @@
#include <projectexplorer/devicesupport/idevice.h>
#include <QCoreApplication>
namespace Utils {
class SshConnectionParameters;
class PortList;
@@ -48,6 +50,7 @@ class LinuxDeviceConfigurationPrivate;
class REMOTELINUX_EXPORT LinuxDeviceConfiguration : public ProjectExplorer::IDevice
{
Q_DECLARE_TR_FUNCTIONS(LinuxDeviceConfiguration)
public:
typedef QSharedPointer<LinuxDeviceConfiguration> Ptr;
typedef QSharedPointer<const LinuxDeviceConfiguration> ConstPtr;
@@ -70,6 +73,11 @@ public:
static Ptr create(const QString &name, const QString &type, MachineType machineType,
Origin origin = ManuallyAdded, const QString &fingerprint = QString());
QString displayType() const;
ProjectExplorer::IDeviceWidget *createWidget();
QStringList actionIds() const;
QString displayNameForActionId(const QString &actionId) const;
QDialog *createAction(const QString &actionId, QWidget *parent) const;
void fromMap(const QVariantMap &map);
ProjectExplorer::IDevice::Ptr clone() const;