Commit 10fc54f3 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Maemo: Use per-target device configuration model.

Now if you have e.g. a Meego target, only Meego device configurations
are selectable in that target's deploy configuration.
Naturally, now the "default" attribute of a device configuration
is per Maemo version.
parent 33d5967a
......@@ -37,6 +37,7 @@
#include "maemodeploystepwidget.h"
#include "maemoglobal.h"
#include "maemopackagecreationstep.h"
#include "maemopertargetdeviceconfigurationlistmodel.h"
#include "maemoremotemounter.h"
#include "maemorunconfiguration.h"
#include "maemotoolchain.h"
......@@ -113,7 +114,7 @@ void MaemoDeployStep::ctor()
}
m_state = Inactive;
m_deviceConfig = MaemoDeviceConfigurations::instance()->defaultDeviceConfig();
m_deviceConfig = maemotarget()->deviceConfigurationsModel()->defaultDeviceConfig();
m_needsInstall = false;
m_sysrootInstaller = new QProcess(this);
connect(m_sysrootInstaller, SIGNAL(finished(int,QProcess::ExitStatus)),
......@@ -136,7 +137,7 @@ void MaemoDeployStep::ctor()
SLOT(handlePortsGathererError(QString)));
connect(m_portsGatherer, SIGNAL(portListReady()), this,
SLOT(handlePortListReady()));
connect(MaemoDeviceConfigurations::instance(), SIGNAL(updated()),
connect(maemotarget()->deviceConfigurationsModel(), SIGNAL(updated()),
SLOT(handleDeviceConfigurationsUpdated()));
}
......@@ -308,17 +309,13 @@ void MaemoDeployStep::handleDeviceConfigurationsUpdated()
void MaemoDeployStep::setDeviceConfig(MaemoDeviceConfig::Id internalId)
{
const MaemoDeviceConfigurations * const devConfs
= MaemoDeviceConfigurations::instance();
m_deviceConfig = devConfs->find(internalId);
if (!m_deviceConfig)
m_deviceConfig = devConfs->defaultDeviceConfig();
m_deviceConfig = maemotarget()->deviceConfigurationsModel()->find(internalId);
emit deviceConfigChanged();
}
void MaemoDeployStep::setDeviceConfig(int i)
{
m_deviceConfig = MaemoDeviceConfigurations::instance()->deviceAt(i);
m_deviceConfig = maemotarget()->deviceConfigurationsModel()->deviceAt(i);
emit deviceConfigChanged();
}
......
......@@ -77,6 +77,7 @@ public:
virtual ~MaemoDeployStep();
QSharedPointer<const MaemoDeviceConfig> deviceConfig() const { return m_deviceConfig; }
const AbstractQt4MaemoTarget *maemotarget() const;
void setDeviceConfig(int i);
bool currentlyNeedsDeployment(const QString &host,
const MaemoDeployable &deployable) const;
......@@ -143,7 +144,6 @@ private:
const MaemoPackageCreationStep *packagingStep() const;
QString deployMountPoint() const;
const AbstractMaemoToolChain *toolChain() const;
const AbstractQt4MaemoTarget *maemotarget() const;
void copyNextFileToDevice();
void installToSysroot();
QString uploadDir() const;
......
......@@ -4,8 +4,11 @@
#include "maemodeploystep.h"
#include "maemodeployablelistmodel.h"
#include "maemodeployables.h"
#include "maemodeviceconfigurations.h"
#include "maemoglobal.h"
#include "maemopertargetdeviceconfigurationlistmodel.h"
#include "maemorunconfiguration.h"
#include "qt4maemotarget.h"
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/target.h>
......@@ -49,7 +52,7 @@ MaemoDeployStepWidget::~MaemoDeployStepWidget()
void MaemoDeployStepWidget::init()
{
ui->deviceConfigComboBox->setModel(MaemoDeviceConfigurations::instance());
ui->deviceConfigComboBox->setModel(m_step->maemotarget()->deviceConfigurationsModel());
connect(m_step, SIGNAL(deviceConfigChanged()), SLOT(handleDeviceUpdate()));
handleDeviceUpdate();
connect(ui->deviceConfigComboBox, SIGNAL(activated(int)), this,
......@@ -62,10 +65,11 @@ void MaemoDeployStepWidget::init()
void MaemoDeployStepWidget::handleDeviceUpdate()
{
const MaemoDeviceConfig::ConstPtr &devConf = m_step->deviceConfig();
const MaemoDeviceConfigurations * const devConfigs
= MaemoDeviceConfigurations::instance();
ui->deviceConfigComboBox->setCurrentIndex(
devConfigs->indexForInternalId(devConfigs->internalId(devConf)));
const MaemoDeviceConfig::Id internalId
= MaemoDeviceConfigurations::instance()->internalId(devConf);
const int newIndex = m_step->maemotarget()->deviceConfigurationsModel()
->indexForInternalId(internalId);
ui->deviceConfigComboBox->setCurrentIndex(newIndex);
emit updateSummary();
}
......
......@@ -453,7 +453,7 @@ void MaemoDeviceConfigurations::addEmulatorDeviceConfiguration(const QString &na
void MaemoDeviceConfigurations::addConfiguration(const MaemoDeviceConfig::Ptr &devConfig)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
if (m_devConfigs.isEmpty())
if (!defaultDeviceConfig(devConfig->osVersion()))
devConfig->m_isDefault = true;
m_devConfigs << devConfig;
endInsertRows();
......@@ -464,12 +464,18 @@ void MaemoDeviceConfigurations::removeConfiguration(int idx)
Q_ASSERT(idx >= 0 && idx < rowCount());
beginRemoveRows(QModelIndex(), idx, idx);
const bool wasDefault = deviceAt(idx)->m_isDefault;
const MaemoGlobal::MaemoVersion osVersion = deviceAt(idx)->osVersion();
m_devConfigs.removeAt(idx);
endRemoveRows();
if (wasDefault && !m_devConfigs.isEmpty()) {
m_devConfigs.first()->m_isDefault = true;
const QModelIndex changedIndex = index(0, 0);
emit dataChanged(changedIndex, changedIndex);
if (wasDefault) {
for (int i = 0; i < m_devConfigs.count(); ++i) {
if (deviceAt(i)->osVersion() == osVersion) {
m_devConfigs.at(i)->m_isDefault = true;
const QModelIndex changedIndex = index(i, 0);
emit dataChanged(changedIndex, changedIndex);
break;
}
}
}
}
......@@ -497,12 +503,14 @@ void MaemoDeviceConfigurations::setPortsSpec(int i, const QString &portsSpec)
void MaemoDeviceConfigurations::setDefaultDevice(int idx)
{
Q_ASSERT(idx >= 0 && idx < rowCount());
if (m_devConfigs.at(idx)->m_isDefault)
const MaemoDeviceConfig::Ptr &devConf = m_devConfigs.at(idx);
if (devConf->m_isDefault)
return;
QModelIndex oldDefaultIndex;
for (int i = 0; i < m_devConfigs.count(); ++i) {
const MaemoDeviceConfig::Ptr &oldDefaultDev = m_devConfigs.at(i);
if (oldDefaultDev->m_isDefault) {
if (oldDefaultDev->m_isDefault
&& oldDefaultDev->osVersion() == devConf->osVersion()) {
oldDefaultDev->m_isDefault = false;
oldDefaultIndex = index(i, 0);
break;
......@@ -510,7 +518,7 @@ void MaemoDeviceConfigurations::setDefaultDevice(int idx)
}
Q_ASSERT(oldDefaultIndex.isValid());
emit dataChanged(oldDefaultIndex, oldDefaultIndex);
m_devConfigs.at(idx)->m_isDefault = true;
devConf->m_isDefault = true;
const QModelIndex newDefaultIndex = index(idx, 0);
emit dataChanged(newDefaultIndex, newDefaultIndex);
}
......@@ -528,18 +536,17 @@ void MaemoDeviceConfigurations::load()
m_defaultSshKeyFilePath = settings->value(DefaultKeyFilePathKey,
MaemoDeviceConfig::defaultPrivateKeyFilePath()).toString();
int count = settings->beginReadArray(ConfigListKey);
bool hasDefault = false;
for (int i = 0; i < count; ++i) {
settings->setArrayIndex(i);
MaemoDeviceConfig::Ptr devConf
= MaemoDeviceConfig::create(*settings, m_nextId);
hasDefault |= devConf->m_isDefault;
m_devConfigs << devConf;
}
settings->endArray();
settings->endGroup();
if (!hasDefault && !m_devConfigs.isEmpty())
m_devConfigs.first()->m_isDefault = true;
ensureDefaultExists(MaemoGlobal::Maemo5);
ensureDefaultExists(MaemoGlobal::Maemo6);
ensureDefaultExists(MaemoGlobal::Meego);
}
MaemoDeviceConfig::ConstPtr MaemoDeviceConfigurations::deviceAt(int idx) const
......@@ -562,13 +569,12 @@ MaemoDeviceConfig::ConstPtr MaemoDeviceConfigurations::find(MaemoDeviceConfig::I
return index == -1 ? MaemoDeviceConfig::ConstPtr() : deviceAt(index);
}
MaemoDeviceConfig::ConstPtr MaemoDeviceConfigurations::defaultDeviceConfig() const
MaemoDeviceConfig::ConstPtr MaemoDeviceConfigurations::defaultDeviceConfig(const MaemoGlobal::MaemoVersion osVersion) const
{
foreach (const MaemoDeviceConfig::ConstPtr &devConf, m_devConfigs) {
if (devConf->m_isDefault)
if (devConf->m_isDefault && devConf->osVersion() == osVersion)
return devConf;
}
Q_ASSERT(m_devConfigs.isEmpty());
return MaemoDeviceConfig::ConstPtr();
}
......@@ -586,6 +592,18 @@ MaemoDeviceConfig::Id MaemoDeviceConfigurations::internalId(MaemoDeviceConfig::C
return devConf ? devConf->m_internalId : MaemoDeviceConfig::InvalidId;
}
void MaemoDeviceConfigurations::ensureDefaultExists(MaemoGlobal::MaemoVersion osVersion)
{
if (!defaultDeviceConfig(osVersion)) {
foreach (const MaemoDeviceConfig::Ptr &devConf, m_devConfigs) {
if (devConf->osVersion() == osVersion) {
devConf->m_isDefault = true;
break;
}
}
}
}
int MaemoDeviceConfigurations::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
......@@ -598,8 +616,10 @@ QVariant MaemoDeviceConfigurations::data(const QModelIndex &index, int role) con
return QVariant();
const MaemoDeviceConfig::ConstPtr devConf = deviceAt(index.row());
QString name = devConf->name();
if (devConf->m_isDefault)
name += tr(" (default)");
if (devConf->m_isDefault) {
name += QLatin1Char(' ') + tr("(default for %1)")
.arg(MaemoGlobal::maemoVersionToString(devConf->osVersion()));
}
return name;
}
......
......@@ -82,6 +82,7 @@ public:
MaemoGlobal::MaemoVersion osVersion() const { return m_osVersion; }
DeviceType type() const { return m_type; }
QString portsSpec() const { return m_portsSpec; }
Id internalId() const { return m_internalId; }
bool isDefault() const { return m_isDefault; }
static QString portsRegExpr();
static QString defaultHost(DeviceType type);
......@@ -137,7 +138,7 @@ public:
MaemoDeviceConfig::ConstPtr deviceAt(int index) const;
MaemoDeviceConfig::ConstPtr find(MaemoDeviceConfig::Id id) const;
MaemoDeviceConfig::ConstPtr defaultDeviceConfig() const;
MaemoDeviceConfig::ConstPtr defaultDeviceConfig(const MaemoGlobal::MaemoVersion osVersion) const;
bool hasConfig(const QString &name) const;
int indexForInternalId(MaemoDeviceConfig::Id internalId) const;
MaemoDeviceConfig::Id internalId(MaemoDeviceConfig::ConstPtr devConf) const;
......@@ -170,6 +171,7 @@ private:
static void copy(const MaemoDeviceConfigurations *source,
MaemoDeviceConfigurations *target, bool deep);
void addConfiguration(const MaemoDeviceConfig::Ptr &devConfig);
void ensureDefaultExists(MaemoGlobal::MaemoVersion osVersion);
static MaemoDeviceConfigurations *m_instance;
MaemoDeviceConfig::Id m_nextId;
......
......@@ -292,8 +292,8 @@ QStringList MaemoGlobal::targetArgs(const QtVersion *qtVersion, bool useTarget)
QString MaemoGlobal::maemoVersionToString(MaemoVersion version)
{
switch (version) {
case Maemo5: return QLatin1String("Maemo 5 (Fremantle)");
case Maemo6: return QLatin1String("Maemo 6 (Harmattan)");
case Maemo5: return QLatin1String("Maemo 5/Fremantle");
case Maemo6: return QLatin1String("Maemo 6/Harmattan");
case Meego: return QLatin1String("Meego");
}
Q_ASSERT(false);
......
......@@ -32,7 +32,6 @@
**************************************************************************/
#include "maemopertargetdeviceconfigurationlistmodel.h"
#include "maemodeviceconfigurations.h"
#include "qt4maemotarget.h"
using namespace ProjectExplorer;
......@@ -40,20 +39,20 @@ using namespace ProjectExplorer;
namespace Qt4ProjectManager {
namespace Internal {
MaemoPerTargetDeviceConfigurationListModel::MaemoPerTargetDeviceConfigurationListModel(const Target *target,
QObject *parent) : QAbstractListModel(parent)
MaemoPerTargetDeviceConfigurationListModel::MaemoPerTargetDeviceConfigurationListModel(Target *target)
: QAbstractListModel(target)
{
if (qobject_cast<const Qt4Maemo5Target *>(target))
if (qobject_cast<Qt4Maemo5Target *>(target))
m_targetOsVersion = MaemoGlobal::Maemo5;
else if (qobject_cast<const Qt4HarmattanTarget *>(target))
else if (qobject_cast<Qt4HarmattanTarget *>(target))
m_targetOsVersion = MaemoGlobal::Maemo6;
else if (qobject_cast<const Qt4MeegoTarget *>(target))
else if (qobject_cast<Qt4MeegoTarget *>(target))
m_targetOsVersion = MaemoGlobal::Meego;
else
Q_ASSERT(false);
const MaemoDeviceConfigurations * const devConfs
= MaemoDeviceConfigurations::instance();
connect(devConfs, SIGNAL(modelReset), this, SIGNAL(modelReset()));
connect(devConfs, SIGNAL(modelReset()), this, SIGNAL(modelReset()));
connect(devConfs, SIGNAL(updated()), this, SIGNAL(updated()));
}
......@@ -77,23 +76,51 @@ QVariant MaemoPerTargetDeviceConfigurationListModel::data(const QModelIndex &ind
{
if (!index.isValid() || index.row() >= rowCount() || role != Qt::DisplayRole)
return QVariant();
const MaemoDeviceConfig::ConstPtr &devConf = deviceAt(index.row());
Q_ASSERT(devConf);
QString displayedName = devConf->name();
if (devConf->isDefault())
displayedName += QLatin1Char(' ') + tr("(default)");
return displayedName;
}
MaemoDeviceConfig::ConstPtr MaemoPerTargetDeviceConfigurationListModel::deviceAt(int idx) const
{
int currentRow = -1;
const MaemoDeviceConfigurations * const devConfs
= MaemoDeviceConfigurations::instance();
const int devConfsCount = devConfs->rowCount();
for (int i = 0; i < devConfsCount; ++i) {
if (devConfs->deviceAt(i)->osVersion() == m_targetOsVersion) {
if (++currentRow == index.row()) {
const MaemoDeviceConfig::ConstPtr &devConf = devConfs->deviceAt(i);
QString displayedName = devConf->name();
if (devConf->isDefault())
displayedName + QLatin1Char(' ') + tr("(default)");
return displayedName;
}
if (++currentRow == idx)
return devConfs->deviceAt(i);
}
}
Q_ASSERT(false);
return QVariant();
return MaemoDeviceConfig::ConstPtr();
}
MaemoDeviceConfig::ConstPtr MaemoPerTargetDeviceConfigurationListModel::defaultDeviceConfig() const
{
return MaemoDeviceConfigurations::instance()->defaultDeviceConfig(m_targetOsVersion);
}
MaemoDeviceConfig::ConstPtr MaemoPerTargetDeviceConfigurationListModel::find(MaemoDeviceConfig::Id id) const
{
const MaemoDeviceConfig::ConstPtr &devConf
= MaemoDeviceConfigurations::instance()->find(id);
return devConf && devConf->osVersion() == m_targetOsVersion
? devConf : defaultDeviceConfig();
}
int MaemoPerTargetDeviceConfigurationListModel::indexForInternalId(MaemoDeviceConfig::Id id) const
{
const int count = rowCount();
for (int i = 0; i < count; ++i) {
if (deviceAt(i)->internalId() == id)
return i;
}
return -1;
}
} // namespace Internal
......
......@@ -33,9 +33,11 @@
#ifndef MAEMOPERTARGETDEVICECONFIGURATIONLISTMODEL_H
#define MAEMOPERTARGETDEVICECONFIGURATIONLISTMODEL_H
#include "maemodeviceconfigurations.h"
#include "maemoglobal.h"
#include <QtCore/QAbstractListModel>
#include <QtCore/QSharedPointer>
namespace ProjectExplorer { class Target; }
......@@ -46,13 +48,17 @@ class MaemoPerTargetDeviceConfigurationListModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit MaemoPerTargetDeviceConfigurationListModel(const ProjectExplorer::Target *target,
QObject *parent = 0);
explicit MaemoPerTargetDeviceConfigurationListModel(ProjectExplorer::Target *target);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index,
int role = Qt::DisplayRole) const;
QSharedPointer<const MaemoDeviceConfig> deviceAt(int idx) const;
QSharedPointer<const MaemoDeviceConfig> defaultDeviceConfig() const;
QSharedPointer<const MaemoDeviceConfig> find(MaemoDeviceConfig::Id id) const;
int indexForInternalId(MaemoDeviceConfig::Id id) const;
signals:
void updated();
......
......@@ -31,6 +31,7 @@
#include "maemoglobal.h"
#include "maemopackagecreationstep.h"
#include "maemopertargetdeviceconfigurationlistmodel.h"
#include "maemorunconfiguration.h"
#include "qt4maemodeployconfiguration.h"
......@@ -297,6 +298,12 @@ bool AbstractQt4MaemoTarget::initPackagingSettingsFromOtherTarget()
return initAdditionalPackagingSettingsFromOtherTarget();
}
void AbstractQt4MaemoTarget::initDeviceConfigurationsModel()
{
m_deviceConfigurationsListModel
= new MaemoPerTargetDeviceConfigurationListModel(this);
}
void AbstractQt4MaemoTarget::raiseError(const QString &reason)
{
QMessageBox::critical(0, tr("Error creating Maemo templates"), reason);
......@@ -989,6 +996,7 @@ Qt4Maemo5Target::Qt4Maemo5Target(Qt4Project *parent, const QString &id)
: AbstractDebBasedQt4MaemoTarget(parent, id)
{
setDisplayName(defaultDisplayName());
initDeviceConfigurationsModel();
}
Qt4Maemo5Target::~Qt4Maemo5Target() {}
......@@ -1008,6 +1016,7 @@ Qt4HarmattanTarget::Qt4HarmattanTarget(Qt4Project *parent, const QString &id)
: AbstractDebBasedQt4MaemoTarget(parent, id)
{
setDisplayName(defaultDisplayName());
initDeviceConfigurationsModel();
}
Qt4HarmattanTarget::~Qt4HarmattanTarget() {}
......@@ -1028,6 +1037,7 @@ Qt4MeegoTarget::Qt4MeegoTarget(Qt4Project *parent, const QString &id)
: AbstractRpmBasedQt4MaemoTarget(parent, id)
{
setDisplayName(defaultDisplayName());
initDeviceConfigurationsModel();
}
Qt4MeegoTarget::~Qt4MeegoTarget() {}
......
......@@ -42,6 +42,7 @@ QT_FORWARD_DECLARE_CLASS(QFileSystemWatcher)
namespace Qt4ProjectManager {
class Qt4Project;
namespace Internal {
class MaemoPerTargetDeviceConfigurationListModel;
class Qt4MaemoDeployConfigurationFactory;
class AbstractQt4MaemoTarget : public Qt4BaseTarget
......@@ -79,7 +80,12 @@ public:
};
DebugArchitecture debugArchitecture() const;
MaemoPerTargetDeviceConfigurationListModel *deviceConfigurationsModel() const {
return m_deviceConfigurationsListModel;
}
protected:
void initDeviceConfigurationsModel();
void raiseError(const QString &reason);
QSharedPointer<QFile> openFile(const QString &filePath,
QIODevice::OpenMode mode, QString *error) const;
......@@ -106,6 +112,7 @@ private:
Qt4BuildConfigurationFactory *m_buildConfigurationFactory;
Qt4MaemoDeployConfigurationFactory *m_deployConfigurationFactory;
MaemoPerTargetDeviceConfigurationListModel * m_deviceConfigurationsListModel;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment