Maemo: Allow user to add target.path if project does not have it.

Task-number: QTCREATORBUG-2704
This commit is contained in:
Christian Kandeler
2010-10-22 13:29:38 +02:00
parent 06843b4c88
commit ee53546d8e
3 changed files with 69 additions and 14 deletions

View File

@@ -30,10 +30,18 @@
#include "maemodeployablelistmodel.h" #include "maemodeployablelistmodel.h"
#include "maemoprofilewrapper.h" #include "maemoprofilewrapper.h"
#include "maemotoolchain.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <qt4projectmanager/qt4buildconfiguration.h>
#include <qt4projectmanager/qt4target.h>
#include <utils/qtcassert.h>
#include <QtCore/QCryptographicHash>
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtGui/QBrush>
namespace Qt4ProjectManager { namespace Qt4ProjectManager {
namespace Internal { namespace Internal {
@@ -159,6 +167,16 @@ QVariant MaemoDeployableListModel::data(const QModelIndex &index, int role) cons
if (!index.isValid() || index.row() >= rowCount()) if (!index.isValid() || index.row() >= rowCount())
return QVariant(); return QVariant();
if (isEditable(index)) {
if (role == Qt::DisplayRole)
return tr("<no target path set>");
if (role == Qt::ForegroundRole) {
QBrush brush;
brush.setColor("red");
return brush;
}
}
const MaemoDeployable &d = deployableAt(index.row()); const MaemoDeployable &d = deployableAt(index.row());
if (index.column() == 0 && role == Qt::DisplayRole) if (index.column() == 0 && role == Qt::DisplayRole)
return QDir::toNativeSeparators(d.localFilePath); return QDir::toNativeSeparators(d.localFilePath);
@@ -170,27 +188,20 @@ QVariant MaemoDeployableListModel::data(const QModelIndex &index, int role) cons
Qt::ItemFlags MaemoDeployableListModel::flags(const QModelIndex &index) const Qt::ItemFlags MaemoDeployableListModel::flags(const QModelIndex &index) const
{ {
Qt::ItemFlags parentFlags = QAbstractTableModel::flags(index); Qt::ItemFlags parentFlags = QAbstractTableModel::flags(index);
// if (index.column() == 1) if (isEditable(index))
// return parentFlags | Qt::ItemIsEditable; return parentFlags | Qt::ItemIsEditable;
return parentFlags; return parentFlags;
} }
bool MaemoDeployableListModel::setData(const QModelIndex &index, bool MaemoDeployableListModel::setData(const QModelIndex &index,
const QVariant &value, int role) const QVariant &value, int role)
{ {
if (!index.isValid() || index.row() >= rowCount() || index.column() != 1 if (!isEditable(index) || role != Qt::EditRole)
|| role != Qt::EditRole)
return false; return false;
const QString &remoteDir = value.toString();
MaemoDeployable &deployable = m_deployables[index.row()]; if (!addTargetPath(remoteDir))
const QString &newRemoteDir = value.toString();
if (!m_proFileWrapper->replaceInstallPath(deployable.remoteDir,
deployable.localFilePath, newRemoteDir)) {
qWarning("Error: Could not update .pro file");
return false; return false;
} m_deployables.first().remoteDir = remoteDir;
deployable.remoteDir = newRemoteDir;
emit dataChanged(index, index); emit dataChanged(index, index);
return true; return true;
} }
@@ -245,5 +256,46 @@ void MaemoDeployableListModel::setProFileUpdateSetting(ProFileUpdateSetting upda
buildModel(); buildModel();
} }
bool MaemoDeployableListModel::isEditable(const QModelIndex &index) const
{
return index.row() == 0 && index.column() == 1
&& m_deployables.first().remoteDir.isEmpty();
}
bool MaemoDeployableListModel::addTargetPath(const QString &remoteDir)
{
QFile projectFile(m_proFilePath);
if (!projectFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
qWarning("Error opening .pro file for writing.");
return false;
}
const ProjectExplorer::Project *const activeProject
= ProjectExplorer::ProjectExplorerPlugin::instance()->session()->startupProject();
QTC_ASSERT(activeProject, return false);
const Qt4Target *const activeTarget
= qobject_cast<Qt4Target *>(activeProject->activeTarget());
QTC_ASSERT(activeTarget, return false);
const Qt4BuildConfiguration *const bc
= activeTarget->activeBuildConfiguration();
QTC_ASSERT(bc, return false);
const MaemoToolChain *const tc
= dynamic_cast<MaemoToolChain *>(bc->toolChain());
QTC_ASSERT(tc, return false);
QString proFileScope;
if (tc->version() == MaemoToolChain::Maemo5)
proFileScope = QLatin1String("maemo5");
else
proFileScope = QLatin1String("unix:!symbian:!maemo5");
const QString proFileString = QString(QLatin1Char('\n') + proFileScope
+ QLatin1String(" {\n target.path = %1\n INSTALLS += target\n}\n"))
.arg(remoteDir);
if (!projectFile.write(proFileString.toLocal8Bit())
|| !projectFile.flush()) {
qWarning("Error updating .pro file.");
return false;
}
return true;
}
} // namespace Qt4ProjectManager } // namespace Qt4ProjectManager
} // namespace Internal } // namespace Internal

View File

@@ -90,7 +90,9 @@ private:
virtual bool setData(const QModelIndex &index, const QVariant &value, virtual bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole); int role = Qt::EditRole);
bool isEditable(const QModelIndex &index) const;
bool buildModel(); bool buildModel();
bool addTargetPath(const QString &remoteDir);
const Qt4ProjectType m_projectType; const Qt4ProjectType m_projectType;
const QString m_proFilePath; const QString m_proFilePath;

View File

@@ -98,6 +98,7 @@ void MaemoDeployStepWidget::setDeployToSysroot(bool doDeploy)
void MaemoDeployStepWidget::handleModelListToBeReset() void MaemoDeployStepWidget::handleModelListToBeReset()
{ {
ui->tableView->reset(); // Otherwise we'll crash if the user is currently editing.
ui->tableView->setModel(0); ui->tableView->setModel(0);
} }