Commit b96df669 authored by ck's avatar ck
Browse files

Maemo: Make device configuration settable from deploy widget.

This is necessary in case there is no run configuration (e.g. for
library projects).
parent 4a9ba8d0
......@@ -32,6 +32,7 @@
#include "maemoconstants.h"
#include "maemodeployables.h"
#include "maemodeploystepwidget.h"
#include "maemodeviceconfiglistmodel.h"
#include "maemoglobal.h"
#include "maemopackagecreationstep.h"
#include "maemorunconfiguration.h"
......@@ -79,6 +80,7 @@ MaemoDeployStep::~MaemoDeployStep()
void MaemoDeployStep::ctor()
{
m_deviceConfigModel = new MaemoDeviceConfigListModel(this);
}
bool MaemoDeployStep::init()
......@@ -104,6 +106,7 @@ QVariantMap MaemoDeployStep::toMap() const
{
QVariantMap map(BuildStep::toMap());
addDeployTimesToMap(map);
map.unite(m_deviceConfigModel->toMap());
return map;
}
......@@ -131,6 +134,7 @@ bool MaemoDeployStep::fromMap(const QVariantMap &map)
if (!BuildStep::fromMap(map))
return false;
getDeployTimesFromMap(map);
m_deviceConfigModel->fromMap(map);
return true;
}
......@@ -213,11 +217,15 @@ void MaemoDeployStep::setDeployed(const QString &host,
MaemoDeviceConfig MaemoDeployStep::deviceConfig() const
{
// TODO: For lib template, get info from config widget
const RunConfiguration * const rc =
buildConfiguration()->target()->activeRunConfiguration();
return rc ? qobject_cast<const MaemoRunConfiguration *>(rc)->deviceConfig()
: MaemoDeviceConfig();
return deviceConfigModel()->current();
}
MaemoDeviceConfigListModel *MaemoDeployStep::deviceConfigModel() const
{
const MaemoRunConfiguration * const rc =
qobject_cast<const MaemoRunConfiguration *>(buildConfiguration()
->target()->activeRunConfiguration());
return rc ? rc->deviceConfigModel() : m_deviceConfigModel;
}
void MaemoDeployStep::start()
......
......@@ -55,6 +55,7 @@ class SshRemoteProcess;
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeployables;
class MaemoDeviceConfigListModel;
class MaemoPackageCreationStep;
class MaemoDeployStep : public ProjectExplorer::BuildStep
......@@ -65,6 +66,7 @@ public:
MaemoDeployStep(ProjectExplorer::BuildConfiguration *bc);
virtual ~MaemoDeployStep();
MaemoDeviceConfig deviceConfig() const;
MaemoDeviceConfigListModel *deviceConfigModel() const;
bool currentlyNeedsDeployment(const QString &host,
const MaemoDeployable &deployable) const;
void setDeployed(const QString &host, const MaemoDeployable &deployable);
......@@ -119,6 +121,7 @@ private:
bool m_stopped;
typedef QPair<MaemoDeployable, QString> DeployablePerHost;
QHash<DeployablePerHost, QDateTime> m_lastDeployed;
MaemoDeviceConfigListModel *m_deviceConfigModel;
};
class MaemoDeployEventHandler : public QObject
......
......@@ -5,6 +5,7 @@
#include "maemodeployablelistmodel.h"
#include "maemodeployablelistwidget.h"
#include "maemodeployables.h"
#include "maemodeviceconfiglistmodel.h"
#include "maemorunconfiguration.h"
#include <projectexplorer/buildconfiguration.h>
......@@ -32,17 +33,33 @@ MaemoDeployStepWidget::~MaemoDeployStepWidget()
void MaemoDeployStepWidget::init()
{
const ProjectExplorer::RunConfiguration * const rc =
m_step->buildConfiguration()->target()->activeRunConfiguration();
if (rc) {
connect(qobject_cast<const MaemoRunConfiguration *>(rc),
SIGNAL(deviceConfigurationChanged(ProjectExplorer::Target *)),
this, SLOT(handleDeviceUpdate()));
}
connectDeviceConfigModel();
connect(m_step->buildConfiguration()->target(),
SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
this, SLOT(connectDeviceConfigModel()));
connect(ui->deviceConfigComboBox, SIGNAL(activated(int)), this,
SLOT(setCurrentDeviceConfig(int)));
}
void MaemoDeployStepWidget::connectDeviceConfigModel()
{
const MaemoDeviceConfigListModel * const oldModel
= qobject_cast<MaemoDeviceConfigListModel *>(ui->deviceConfigComboBox->model());
if (oldModel)
disconnect(oldModel, 0, this, 0);
MaemoDeviceConfigListModel * const devModel = m_step->deviceConfigModel();
ui->deviceConfigComboBox->setModel(devModel);
connect(devModel, SIGNAL(currentChanged()), this,
SLOT(handleDeviceUpdate()));
connect(devModel, SIGNAL(modelReset()), this,
SLOT(handleDeviceUpdate()));
handleDeviceUpdate();
}
void MaemoDeployStepWidget::handleDeviceUpdate()
{
ui->deviceConfigComboBox->setCurrentIndex(m_step->deviceConfigModel()
->currentIndex());
emit updateSummary();
}
......@@ -68,5 +85,10 @@ void MaemoDeployStepWidget::handleModelsCreated()
}
}
void MaemoDeployStepWidget::setCurrentDeviceConfig(int index)
{
m_step->deviceConfigModel()->setCurrentIndex(index);
}
} // namespace Internal
} // namespace Qt4ProjectManager
......@@ -22,13 +22,15 @@ public:
~MaemoDeployStepWidget();
private:
Q_SLOT void handleDeviceUpdate();
Q_SLOT void handleModelsCreated();
Q_SLOT void handleDeviceConfigModelChanged();
Q_SLOT void setCurrentDeviceConfig(int index);
virtual void init();
virtual QString summaryText() const;
virtual QString displayName() const;
Q_SLOT void handleDeviceUpdate();
Ui::MaemoDeployStepWidget *ui;
MaemoDeployStep * const m_step;
};
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>469</width>
<height>330</height>
</rect>
</property>
<property name="windowTitle">
......@@ -15,7 +15,34 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="deviceConfigLabel">
<property name="text">
<string>Device configuration:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="deviceConfigComboBox"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="installLabel">
<property name="toolTip">
<string>These show the INSTALLS settings from the project file(s).</string>
</property>
......
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "maemodeviceconfiglistmodel.h"
#include "maemoconstants.h"
namespace Qt4ProjectManager {
namespace Internal {
MaemoDeviceConfigListModel::MaemoDeviceConfigListModel(QObject *parent)
: QAbstractListModel(parent), m_currentIndex(-1)
{
const MaemoDeviceConfigurations &devConfs
= MaemoDeviceConfigurations::instance();
if (devConfs.devConfigs().isEmpty())
setInvalid();
else
setCurrentIndex(0);
connect(&devConfs, SIGNAL(updated()), this,
SLOT(handleDeviceConfigListChange()));
}
void MaemoDeviceConfigListModel::setCurrentIndex(int index)
{
if (index != m_currentIndex) {
m_currentIndex = index;
m_currentId = MaemoDeviceConfigurations::instance().devConfigs()
.at(m_currentIndex).internalId;
emit currentChanged();
}
}
void MaemoDeviceConfigListModel::resetCurrentIndex()
{
const QList<MaemoDeviceConfig> &devConfigs
= MaemoDeviceConfigurations::instance().devConfigs();
if (devConfigs.isEmpty()) {
setInvalid();
return;
}
for (int i = 0; i < devConfigs.count(); ++i) {
if (devConfigs.at(i).internalId == m_currentId) {
setCurrentIndex(i);
return;
}
}
setCurrentIndex(0);
}
void MaemoDeviceConfigListModel::setInvalid()
{
m_currentIndex = -1;
m_currentId = MaemoDeviceConfig::InvalidId;
emit currentChanged();
}
MaemoDeviceConfig MaemoDeviceConfigListModel::current() const
{
return MaemoDeviceConfigurations::instance().find(m_currentId);
}
QVariantMap MaemoDeviceConfigListModel::toMap() const
{
QVariantMap map;
map.insert(DeviceIdKey, current().internalId);
return map;
}
void MaemoDeviceConfigListModel::fromMap(const QVariantMap &map)
{
const quint64 oldId = m_currentId;
m_currentId = map.value(DeviceIdKey, 0).toULongLong();
resetCurrentIndex();
if (oldId != m_currentId)
emit currentChanged();
}
void MaemoDeviceConfigListModel::handleDeviceConfigListChange()
{
resetCurrentIndex();
reset();
emit currentChanged();
}
int MaemoDeviceConfigListModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0
: MaemoDeviceConfigurations::instance().devConfigs().count();
}
QVariant MaemoDeviceConfigListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= rowCount()
|| role != Qt::DisplayRole)
return QString();
return MaemoDeviceConfigurations::instance().devConfigs().at(index.row()).name;
}
} // namespace Internal
} // namespace Qt4ProjectManager
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MAEMODEVICECONFIGLISTMODEL_H
#define MAEMODEVICECONFIGLISTMODEL_H
#include "maemodeviceconfigurations.h"
#include <QtCore/QAbstractListModel>
#include <QtCore/QVariantMap>
namespace Qt4ProjectManager {
namespace Internal {
class MaemoDeviceConfigListModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit MaemoDeviceConfigListModel(QObject *parent = 0);
void setCurrentIndex(int index);
MaemoDeviceConfig current() const;
int currentIndex() const { return m_currentIndex; }
QVariantMap toMap() const;
void fromMap(const QVariantMap &map);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role) const;
signals:
void currentChanged();
private:
Q_SLOT void handleDeviceConfigListChange();
void resetCurrentIndex();
void setInvalid();
quint64 m_currentId;
int m_currentIndex;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // MAEMODEVICECONFIGLISTMODEL_H
......@@ -58,6 +58,8 @@ public:
void save(QSettings &settings) const;
bool isValid() const;
static const quint64 InvalidId = 0;
Core::SshConnectionParameters server;
QString name;
DeviceType type;
......@@ -69,7 +71,6 @@ private:
int defaultGdbServerPort(DeviceType type) const;
QString defaultHost(DeviceType type) const;
static const quint64 InvalidId = 0;
};
class DevConfNameMatcher
......
......@@ -31,6 +31,7 @@
#include "maemodeployables.h"
#include "maemodeploystep.h"
#include "maemodeviceconfiglistmodel.h"
#include "maemoglobal.h"
#include "maemorunconfigurationwidget.h"
#include "maemotoolchain.h"
......@@ -68,7 +69,6 @@ MaemoRunConfiguration::MaemoRunConfiguration(Qt4Target *parent,
: RunConfiguration(parent, source)
, m_proFilePath(source->m_proFilePath)
, m_gdbPath(source->m_gdbPath)
, m_devConfig(source->m_devConfig)
, m_arguments(source->m_arguments)
{
init();
......@@ -76,10 +76,13 @@ MaemoRunConfiguration::MaemoRunConfiguration(Qt4Target *parent,
void MaemoRunConfiguration::init()
{
m_devConfigModel = new MaemoDeviceConfigListModel(this);
setDisplayName(QFileInfo(m_proFilePath).completeBaseName());
updateDeviceConfigurations();
connect(&MaemoDeviceConfigurations::instance(), SIGNAL(updated()), this,
connect(m_devConfigModel, SIGNAL(currentChanged()), this,
SLOT(updateDeviceConfigurations()));
connect(m_devConfigModel, SIGNAL(modelReset()), this,
SLOT(updateDeviceConfigurations()));
connect(qt4Target()->qt4Project(),
......@@ -128,10 +131,10 @@ void MaemoRunConfiguration::proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFil
QVariantMap MaemoRunConfiguration::toMap() const
{
QVariantMap map(RunConfiguration::toMap());
map.insert(DeviceIdKey, m_devConfig.internalId);
map.insert(ArgumentsKey, m_arguments);
const QDir dir = QDir(target()->project()->projectDirectory());
map.insert(ProFileKey, dir.relativeFilePath(m_proFilePath));
map.unite(m_devConfigModel->toMap());
return map;
}
......@@ -140,24 +143,22 @@ bool MaemoRunConfiguration::fromMap(const QVariantMap &map)
if (!RunConfiguration::fromMap(map))
return false;
setDeviceConfig(MaemoDeviceConfigurations::instance().
find(map.value(DeviceIdKey, 0).toInt()));
m_arguments = map.value(ArgumentsKey).toStringList();
const QDir dir = QDir(target()->project()->projectDirectory());
m_proFilePath = dir.filePath(map.value(ProFileKey).toString());
m_devConfigModel->fromMap(map);
return true;
}
void MaemoRunConfiguration::setDeviceConfig(const MaemoDeviceConfig &devConf)
MaemoDeviceConfig MaemoRunConfiguration::deviceConfig() const
{
m_devConfig = devConf;
emit deviceConfigurationChanged(target());
return m_devConfigModel->current();
}
MaemoDeviceConfig MaemoRunConfiguration::deviceConfig() const
MaemoDeviceConfigListModel *MaemoRunConfiguration::deviceConfigModel() const
{
return m_devConfig;
return m_devConfigModel;
}
const MaemoToolChain *MaemoRunConfiguration::toolchain() const
......@@ -251,16 +252,7 @@ void MaemoRunConfiguration::setArguments(const QStringList &args)
void MaemoRunConfiguration::updateDeviceConfigurations()
{
const MaemoDeviceConfigurations &configManager
= MaemoDeviceConfigurations::instance();
if (!m_devConfig.isValid()) {
const QList<MaemoDeviceConfig> &configList = configManager.devConfigs();
if (!configList.isEmpty())
m_devConfig = configList.first();
} else {
m_devConfig = configManager.find(m_devConfig.internalId);
}
emit deviceConfigurationsUpdated(target());
emit deviceConfigurationChanged(target());
}
} // namespace Internal
......
......@@ -47,15 +47,16 @@ class Qt4Project;
namespace Internal {
class MaemoManager;
class MaemoToolChain;
class Qt4BuildConfiguration;
class Qt4ProFileNode;
class Qt4Target;
class MaemoDeviceConfigListModel;
class MaemoDeployStep;
class MaemoManager;
class MaemoPackageCreationStep;
class MaemoRunConfigurationFactory;
class MaemoToolChain;
class MaemoRunConfiguration : public ProjectExplorer::RunConfiguration
{
......@@ -81,8 +82,8 @@ public:
const QString targetRoot() const;
const QStringList arguments() const;
void setArguments(const QStringList &args);
void setDeviceConfig(const MaemoDeviceConfig &deviceConfig);
MaemoDeviceConfig deviceConfig() const;
MaemoDeviceConfigListModel *deviceConfigModel() const;
QString runtimeGdbServerPort() const;
const QString gdbCmd() const;
......@@ -91,7 +92,6 @@ public:
virtual QVariantMap toMap() const;
signals:
void deviceConfigurationsUpdated(ProjectExplorer::Target *target);
void deviceConfigurationChanged(ProjectExplorer::Target *target);
void targetInformationChanged() const;
......@@ -109,8 +109,7 @@ private:
QString m_proFilePath;
mutable QString m_gdbPath;
MaemoDeviceConfig m_devConfig;
MaemoDeviceConfigListModel *m_devConfigModel;
QStringList m_arguments;
};
......
......@@ -34,7 +34,7 @@
#include "maemorunconfigurationwidget.h"
#include "maemodeviceconfigurations.h"
#include "maemodeviceconfiglistmodel.h"
#include "maemomanager.h"
#include "maemorunconfiguration.h"
#include "maemosettingspage.h"
......@@ -70,6 +70,7 @@ MaemoRunConfigurationWidget::MaemoRunConfigurationWidget(
QHBoxLayout *devConfLayout = new QHBoxLayout(devConfWidget);
m_devConfBox = new QComboBox;
m_devConfBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
m_devConfBox->setModel(runConfiguration->deviceConfigModel());
devConfLayout->setMargin(0);
devConfLayout->addWidget(m_devConfBox);
QLabel *addDevConfLabel= new QLabel(tr("<a href=\"%1\">Manage device configurations</a>")
......@@ -88,16 +89,15 @@ MaemoRunConfigurationWidget::MaemoRunConfigurationWidget(
m_argsLineEdit = new QLineEdit(m_runConfiguration->arguments().join(" "));
mainLayout->addRow(tr("Arguments:"), m_argsLineEdit);
resetDeviceConfigurations();
connect(m_runConfiguration, SIGNAL(deviceConfigurationsUpdated(ProjectExplorer::Target *)),
this, SLOT(resetDeviceConfigurations()));
handleCurrentDeviceConfigChanged();
connect(m_configNameLineEdit, SIGNAL(textEdited(QString)), this,
SLOT(configNameEdited(QString)));
connect(m_argsLineEdit, SIGNAL(textEdited(QString)), this,
SLOT(argumentsEdited(QString)));
connect(m_devConfBox, SIGNAL(activated(QString)), this,
SLOT(deviceConfigurationChanged(QString)));