diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.cpp index 10cb5e38b5965fb741f913368cc53192f3fb732e..aecec515729665ec0948328b930fe40c548a5952 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.cpp @@ -30,10 +30,18 @@ #include "maemodeployablelistmodel.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/QFileInfo> +#include <QtGui/QBrush> namespace Qt4ProjectManager { namespace Internal { @@ -159,6 +167,16 @@ QVariant MaemoDeployableListModel::data(const QModelIndex &index, int role) cons if (!index.isValid() || index.row() >= rowCount()) 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()); if (index.column() == 0 && role == Qt::DisplayRole) 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 parentFlags = QAbstractTableModel::flags(index); -// if (index.column() == 1) -// return parentFlags | Qt::ItemIsEditable; + if (isEditable(index)) + return parentFlags | Qt::ItemIsEditable; return parentFlags; } bool MaemoDeployableListModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (!index.isValid() || index.row() >= rowCount() || index.column() != 1 - || role != Qt::EditRole) + if (!isEditable(index) || role != Qt::EditRole) return false; - - MaemoDeployable &deployable = m_deployables[index.row()]; - const QString &newRemoteDir = value.toString(); - if (!m_proFileWrapper->replaceInstallPath(deployable.remoteDir, - deployable.localFilePath, newRemoteDir)) { - qWarning("Error: Could not update .pro file"); + const QString &remoteDir = value.toString(); + if (!addTargetPath(remoteDir)) return false; - } - - deployable.remoteDir = newRemoteDir; + m_deployables.first().remoteDir = remoteDir; emit dataChanged(index, index); return true; } @@ -245,5 +256,46 @@ void MaemoDeployableListModel::setProFileUpdateSetting(ProFileUpdateSetting upda 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 Internal diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.h b/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.h index 9d9022e0afaf9cdb3212313ac7cf870ecf6f4c31..3bb92b6cf07ac286764f0e19127768a8715b7973 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeployablelistmodel.h @@ -90,7 +90,9 @@ private: virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + bool isEditable(const QModelIndex &index) const; bool buildModel(); + bool addTargetPath(const QString &remoteDir); const Qt4ProjectType m_projectType; const QString m_proFilePath; diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeploystepwidget.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemodeploystepwidget.cpp index 15482ed2d9840fec6f3c4b3ce47e79bd17f765d0..f2349bf9cc99015e5601d55f26d4a2283289852b 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemodeploystepwidget.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeploystepwidget.cpp @@ -98,6 +98,7 @@ void MaemoDeployStepWidget::setDeployToSysroot(bool doDeploy) void MaemoDeployStepWidget::handleModelListToBeReset() { + ui->tableView->reset(); // Otherwise we'll crash if the user is currently editing. ui->tableView->setModel(0); }