Device: Add create method to IDeviceFactory

Add a create method to the IDeviceFactory and make it replace the
createWizard method. The create method may or may not pop up a wizard.

Remove IDeviceWizard as suggested by Christian.

This patch also adds a canCreate() method to check whether a factory should
be asked to create something or not.

Change-Id: Iaf16aa407530022e8f3804093b58dc3f120f7599
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
Tobias Hunger
2012-03-26 14:01:58 +02:00
parent 866cc42154
commit 1f4caf5399
17 changed files with 66 additions and 95 deletions

View File

@@ -53,9 +53,17 @@ QString MaddeDeviceConfigurationFactory::displayName() const
return tr("Device with MADDE support (Fremantle, Harmattan, MeeGo)"); return tr("Device with MADDE support (Fremantle, Harmattan, MeeGo)");
} }
IDeviceWizard *MaddeDeviceConfigurationFactory::createWizard(QWidget *parent) const bool MaddeDeviceConfigurationFactory::canCreate() const
{ {
return new MaemoDeviceConfigWizard(parent); return true;
}
IDevice::Ptr MaddeDeviceConfigurationFactory::create() const
{
MaemoDeviceConfigWizard *wizard = new MaemoDeviceConfigWizard;
if (wizard->exec() != QDialog::Accepted)
return IDevice::Ptr();
return wizard->device();
} }
IDevice::Ptr MaddeDeviceConfigurationFactory::loadDevice(const QVariantMap &map) const IDevice::Ptr MaddeDeviceConfigurationFactory::loadDevice(const QVariantMap &map) const

View File

@@ -44,7 +44,8 @@ public:
MaddeDeviceConfigurationFactory(QObject *parent = 0); MaddeDeviceConfigurationFactory(QObject *parent = 0);
QString displayName() const; QString displayName() const;
ProjectExplorer::IDeviceWizard *createWizard(QWidget *parent) const; bool canCreate() const;
ProjectExplorer::IDevice::Ptr create() const;
ProjectExplorer::IDevice::Ptr loadDevice(const QVariantMap &map) const; ProjectExplorer::IDevice::Ptr loadDevice(const QVariantMap &map) const;
bool supportsDeviceType(const QString &type) const; bool supportsDeviceType(const QString &type) const;
}; };

View File

@@ -539,7 +539,7 @@ struct MaemoDeviceConfigWizardPrivate
MaemoDeviceConfigWizard::MaemoDeviceConfigWizard(QWidget *parent) MaemoDeviceConfigWizard::MaemoDeviceConfigWizard(QWidget *parent)
: IDeviceWizard(parent), d(new MaemoDeviceConfigWizardPrivate(this)) : QWizard(parent), d(new MaemoDeviceConfigWizardPrivate(this))
{ {
setWindowTitle(tr("New Device Configuration Setup")); setWindowTitle(tr("New Device Configuration Setup"));
setPage(StartPageId, &d->startPage); setPage(StartPageId, &d->startPage);

View File

@@ -33,14 +33,15 @@
#define MAEMODEVICECONFIGWIZARD_H #define MAEMODEVICECONFIGWIZARD_H
#include <projectexplorer/devicesupport/idevice.h> #include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/devicesupport/idevicewizard.h>
#include <QWizard>
namespace Madde { namespace Madde {
namespace Internal { namespace Internal {
struct MaemoDeviceConfigWizardPrivate; struct MaemoDeviceConfigWizardPrivate;
class MaemoDeviceConfigWizard : public ProjectExplorer::IDeviceWizard class MaemoDeviceConfigWizard : public QWizard
{ {
Q_OBJECT Q_OBJECT

View File

@@ -52,6 +52,8 @@ DeviceFactorySelectionDialog::DeviceFactorySelectionDialog(QWidget *parent) :
const QList<IDeviceFactory *> &factories const QList<IDeviceFactory *> &factories
= ExtensionSystem::PluginManager::instance()->getObjects<IDeviceFactory>(); = ExtensionSystem::PluginManager::instance()->getObjects<IDeviceFactory>();
foreach (const IDeviceFactory * const factory, factories) { foreach (const IDeviceFactory * const factory, factories) {
if (!factory->canCreate())
continue;
m_factories << factory; m_factories << factory;
ui->listWidget->addItem(factory->displayName()); ui->listWidget->addItem(factory->displayName());
} }

View File

@@ -39,6 +39,7 @@
#include <QObject> #include <QObject>
namespace ProjectExplorer { namespace ProjectExplorer {
class IDevice;
class IDeviceFactory; class IDeviceFactory;
namespace Internal { namespace Internal {
@@ -51,6 +52,7 @@ class PROJECTEXPLORER_EXPORT DeviceManager : public QObject
Q_OBJECT Q_OBJECT
friend class Internal::DeviceSettingsWidget; friend class Internal::DeviceSettingsWidget;
friend class IDevice; friend class IDevice;
public: public:
~DeviceManager(); ~DeviceManager();

View File

@@ -37,7 +37,6 @@
#include "idevice.h" #include "idevice.h"
#include "idevicefactory.h" #include "idevicefactory.h"
#include "idevicewidget.h" #include "idevicewidget.h"
#include "idevicewizard.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
@@ -137,6 +136,17 @@ void DeviceSettingsWidget::initGui()
m_ui->configurationComboBox->setModel(model); m_ui->configurationComboBox->setModel(model);
m_ui->nameLineEdit->setValidator(m_nameValidator); m_ui->nameLineEdit->setValidator(m_nameValidator);
bool hasDeviceFactories = false;
const QList<IDeviceFactory *> &factories
= ExtensionSystem::PluginManager::instance()->getObjects<IDeviceFactory>();
foreach (const IDeviceFactory *f, factories) {
if (f->canCreate()) {
hasDeviceFactories = true;
break;
}
}
m_ui->addConfigButton->setEnabled(hasDeviceFactories);
int lastIndex = Core::ICore::settings() int lastIndex = Core::ICore::settings()
->value(QLatin1String(LastDeviceIndexKey), 0).toInt(); ->value(QLatin1String(LastDeviceIndexKey), 0).toInt();
if (lastIndex == -1) if (lastIndex == -1)
@@ -152,21 +162,15 @@ void DeviceSettingsWidget::initGui()
void DeviceSettingsWidget::addDevice() void DeviceSettingsWidget::addDevice()
{ {
const QList<IDeviceFactory *> &factories
= ExtensionSystem::PluginManager::instance()->getObjects<IDeviceFactory>();
if (factories.isEmpty()) // Can't happen, because this plugin provides the generic one.
return;
DeviceFactorySelectionDialog d; DeviceFactorySelectionDialog d;
if (d.exec() != QDialog::Accepted) if (d.exec() != QDialog::Accepted)
return; return;
const QScopedPointer<IDeviceWizard> wizard(d.selectedFactory()->createWizard(this)); IDevice::Ptr device = d.selectedFactory()->create();
if (wizard->exec() != QDialog::Accepted) if (device.isNull())
return; return;
m_deviceManager->addDevice(wizard->device()); m_deviceManager->addDevice(device);
m_ui->removeConfigButton->setEnabled(true); m_ui->removeConfigButton->setEnabled(true);
m_ui->configurationComboBox->setCurrentIndex(m_ui->configurationComboBox->count()-1); m_ui->configurationComboBox->setCurrentIndex(m_ui->configurationComboBox->count()-1);
} }

View File

@@ -167,7 +167,7 @@ IDevice::IDevice() : d(new Internal::IDevicePrivate)
{ {
} }
IDevice::IDevice(const QString &type, Origin origin, const QString fingerprint) IDevice::IDevice(const QString &type, Origin origin, const QString &fingerprint)
: d(new Internal::IDevicePrivate) : d(new Internal::IDevicePrivate)
{ {
d->type = type; d->type = type;
@@ -193,6 +193,8 @@ QString IDevice::displayName() const
void IDevice::setDisplayName(const QString &name) void IDevice::setDisplayName(const QString &name)
{ {
if (d->displayName == name)
return;
d->displayName = name; d->displayName = name;
} }

View File

@@ -74,6 +74,7 @@ public:
virtual QStringList actionIds() const = 0; virtual QStringList actionIds() const = 0;
virtual QString displayNameForActionId(const QString &actionId) const = 0; virtual QString displayNameForActionId(const QString &actionId) const = 0;
virtual QDialog *createAction(const QString &actionId, QWidget *parent = 0) const = 0; virtual QDialog *createAction(const QString &actionId, QWidget *parent = 0) const = 0;
virtual void fromMap(const QVariantMap &map); virtual void fromMap(const QVariantMap &map);
virtual Ptr clone() const = 0; virtual Ptr clone() const = 0;
@@ -83,7 +84,7 @@ public:
protected: protected:
IDevice(); IDevice();
IDevice(const QString &type, Origin origin, const QString fingerprint = QString()); IDevice(const QString &type, Origin origin, const QString &fingerprint = QString());
IDevice(const IDevice &other); IDevice(const IDevice &other);
Ptr sharedFromThis(); Ptr sharedFromThis();

View File

@@ -43,7 +43,7 @@ class QWidget;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace ProjectExplorer { namespace ProjectExplorer {
class IDeviceWizard; class IDeviceWidget;
/*! /*!
\class ProjectExplorer::IDeviceFactory \class ProjectExplorer::IDeviceFactory
@@ -65,9 +65,15 @@ public:
virtual QString displayName() const = 0; virtual QString displayName() const = 0;
/*! /*!
A wizard that can create the types of device this factory supports. Check whether this factory can create new devices. This is used to hide
*/ auto-detect-only factories from the listing of possible devices to create.
virtual IDeviceWizard *createWizard(QWidget *parent = 0) const = 0; */
virtual bool canCreate() const = 0;
/*!
Create a new device. This may or may not open a wizard.
*/
virtual IDevice::Ptr create() const = 0;
/*! /*!
Loads a device from a serialized state. The device must be of a matching type. Loads a device from a serialized state. The device must be of a matching type.

View File

@@ -1,64 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef IDEVICEWIZARD_H
#define IDEVICEWIZARD_H
#include "idevice.h"
#include <projectexplorer/projectexplorer_export.h>
#include <QWizard>
namespace ProjectExplorer {
/*!
\class ProjectExplorer::IDeviceWizard
\brief Provides an interface for wizards creating an IDevice subclass.
A class implementing this interface is a wizard whose final result is
an \c IDevice object. The wizard will be started when the user chooses the
"Add..." action from the "Devices" options page.
*/
class PROJECTEXPLORER_EXPORT IDeviceWizard : public QWizard
{
Q_OBJECT
public:
virtual IDevice::Ptr device() = 0;
protected:
IDeviceWizard(QWidget *parent) : QWizard(parent) { }
};
} // namespace ProjectExplorer
#endif // IDEVICEWIZARD_H

View File

@@ -108,7 +108,6 @@ HEADERS += projectexplorer.h \
settingsaccessor.h \ settingsaccessor.h \
environmentitemswidget.h \ environmentitemswidget.h \
devicesupport/idevice.h \ devicesupport/idevice.h \
devicesupport/idevicewizard.h \
devicesupport/idevicewidget.h \ devicesupport/idevicewidget.h \
devicesupport/idevicefactory.h \ devicesupport/idevicefactory.h \
devicesupport/devicemanager.h \ devicesupport/devicemanager.h \

View File

@@ -286,7 +286,6 @@ QtcPlugin {
"devicesupport/devicesettingswidget.cpp", "devicesupport/devicesettingswidget.cpp",
"devicesupport/devicesettingswidget.h", "devicesupport/devicesettingswidget.h",
"devicesupport/devicesettingswidget.ui", "devicesupport/devicesettingswidget.ui",
"devicesupport/idevicewizard.h",
"devicesupport/idevicewidget.h", "devicesupport/idevicewidget.h",
"devicesupport/idevicefactory.h" "devicesupport/idevicefactory.h"
] ]

View File

@@ -51,9 +51,17 @@ QString GenericLinuxDeviceConfigurationFactory::displayName() const
return tr("Generic Linux Device"); return tr("Generic Linux Device");
} }
IDeviceWizard *GenericLinuxDeviceConfigurationFactory::createWizard(QWidget *parent) const bool GenericLinuxDeviceConfigurationFactory::canCreate() const
{ {
return new GenericLinuxDeviceConfigurationWizard(parent); return true;
}
IDevice::Ptr GenericLinuxDeviceConfigurationFactory::create() const
{
GenericLinuxDeviceConfigurationWizard *wizard = new GenericLinuxDeviceConfigurationWizard;
if (wizard->exec() != QDialog::Accepted)
return IDevice::Ptr();
return wizard->device();
} }
IDevice::Ptr GenericLinuxDeviceConfigurationFactory::loadDevice(const QVariantMap &map) const IDevice::Ptr GenericLinuxDeviceConfigurationFactory::loadDevice(const QVariantMap &map) const

View File

@@ -47,7 +47,8 @@ public:
GenericLinuxDeviceConfigurationFactory(QObject *parent = 0); GenericLinuxDeviceConfigurationFactory(QObject *parent = 0);
QString displayName() const; QString displayName() const;
ProjectExplorer::IDeviceWizard *createWizard(QWidget *parent) const; bool canCreate() const;
ProjectExplorer::IDevice::Ptr create() const;
ProjectExplorer::IDevice::Ptr loadDevice(const QVariantMap &map) const; ProjectExplorer::IDevice::Ptr loadDevice(const QVariantMap &map) const;
bool supportsDeviceType(const QString &deviceType) const; bool supportsDeviceType(const QString &deviceType) const;
}; };

View File

@@ -60,7 +60,7 @@ public:
} // namespace Internal } // namespace Internal
GenericLinuxDeviceConfigurationWizard::GenericLinuxDeviceConfigurationWizard(QWidget *parent) GenericLinuxDeviceConfigurationWizard::GenericLinuxDeviceConfigurationWizard(QWidget *parent)
: IDeviceWizard(parent), : QWizard(parent),
d(new Internal::GenericLinuxDeviceConfigurationWizardPrivate(this)) d(new Internal::GenericLinuxDeviceConfigurationWizardPrivate(this))
{ {
setWindowTitle(tr("New Generic Linux Device Configuration Setup")); setWindowTitle(tr("New Generic Linux Device Configuration Setup"));

View File

@@ -33,15 +33,16 @@
#include "remotelinux_export.h" #include "remotelinux_export.h"
#include <projectexplorer/devicesupport/idevicewizard.h> #include <projectexplorer/devicesupport/idevice.h>
#include <QWizard>
namespace RemoteLinux { namespace RemoteLinux {
namespace Internal { namespace Internal {
class GenericLinuxDeviceConfigurationWizardPrivate; class GenericLinuxDeviceConfigurationWizardPrivate;
} // namespace Internal } // namespace Internal
class REMOTELINUX_EXPORT GenericLinuxDeviceConfigurationWizard class REMOTELINUX_EXPORT GenericLinuxDeviceConfigurationWizard : public QWizard
: public ProjectExplorer::IDeviceWizard
{ {
Q_OBJECT Q_OBJECT