forked from qt-creator/qt-creator
Maemo: Move .pro file operations into their own class.
This commit is contained in:
@@ -31,14 +31,12 @@
|
|||||||
|
|
||||||
#include "maemopackagecreationstep.h"
|
#include "maemopackagecreationstep.h"
|
||||||
#include "maemotoolchain.h"
|
#include "maemotoolchain.h"
|
||||||
|
#include "profilewrapper.h"
|
||||||
|
|
||||||
#include <qt4projectmanager/profilereader.h>
|
|
||||||
#include <qt4projectmanager/qt4buildconfiguration.h>
|
#include <qt4projectmanager/qt4buildconfiguration.h>
|
||||||
#include <qt4projectmanager/qt4project.h>
|
#include <qt4projectmanager/qt4project.h>
|
||||||
#include <qt4projectmanager/qt4target.h>
|
#include <qt4projectmanager/qt4target.h>
|
||||||
|
|
||||||
#include <prowriter.h>
|
|
||||||
|
|
||||||
#include <QtCore/QCryptographicHash>
|
#include <QtCore/QCryptographicHash>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
@@ -64,47 +62,32 @@ namespace Internal {
|
|||||||
MaemoPackageContents::MaemoPackageContents(MaemoPackageCreationStep *packageStep)
|
MaemoPackageContents::MaemoPackageContents(MaemoPackageCreationStep *packageStep)
|
||||||
: QAbstractTableModel(packageStep),
|
: QAbstractTableModel(packageStep),
|
||||||
m_packageStep(packageStep),
|
m_packageStep(packageStep),
|
||||||
m_proFileOption(new ProFileOption),
|
|
||||||
m_proFileReader(new ProFileReader(m_proFileOption.data())),
|
|
||||||
m_modified(false),
|
m_modified(false),
|
||||||
m_proFile(0)
|
m_initialized(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MaemoPackageContents::~MaemoPackageContents() {}
|
MaemoPackageContents::~MaemoPackageContents() {}
|
||||||
|
|
||||||
bool MaemoPackageContents::init()
|
|
||||||
{
|
|
||||||
return m_proFile ? true : buildModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MaemoPackageContents::buildModel() const
|
bool MaemoPackageContents::buildModel() const
|
||||||
{
|
{
|
||||||
|
if (m_initialized)
|
||||||
|
return true;
|
||||||
|
|
||||||
m_deployables.clear();
|
m_deployables.clear();
|
||||||
const Qt4ProFileNode * const proFileNode = m_packageStep
|
QSharedPointer<ProFileWrapper> proFileWrapper
|
||||||
->qt4BuildConfiguration()->qt4Target()->qt4Project()->rootProjectNode();
|
= m_packageStep->proFileWrapper();
|
||||||
if (m_proFileName.isEmpty()) {
|
const QStringList &elemList = proFileWrapper->varValues(InstallsVar);
|
||||||
m_proFileName = proFileNode->path();
|
|
||||||
m_proDir = QFileInfo(m_proFileName).dir();
|
|
||||||
}
|
|
||||||
|
|
||||||
resetProFileContents();
|
|
||||||
if (!m_proFile)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const QStringList elemList = m_proFileReader->values(InstallsVar, m_proFile);
|
|
||||||
bool targetFound = false;
|
bool targetFound = false;
|
||||||
foreach (const QString &elem, elemList) {
|
foreach (const QString &elem, elemList) {
|
||||||
const QStringList paths
|
const QStringList &paths = proFileWrapper->varValues(pathVar(elem));
|
||||||
= m_proFileReader->values(pathVar(elem), m_proFile);
|
|
||||||
if (paths.count() != 1) {
|
if (paths.count() != 1) {
|
||||||
qWarning("Error: Variable %s has %d values.",
|
qWarning("Error: Variable %s has %d values.",
|
||||||
qPrintable(pathVar(elem)), paths.count());
|
qPrintable(pathVar(elem)), paths.count());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList files
|
const QStringList &files = proFileWrapper->varValues(filesVar(elem));
|
||||||
= m_proFileReader->values(filesVar(elem), m_proFile);
|
|
||||||
if (files.isEmpty() && elem != TargetVar) {
|
if (files.isEmpty() && elem != TargetVar) {
|
||||||
qWarning("Error: Variable %s has no RHS.",
|
qWarning("Error: Variable %s has no RHS.",
|
||||||
qPrintable(filesVar(elem)));
|
qPrintable(filesVar(elem)));
|
||||||
@@ -117,29 +100,29 @@ bool MaemoPackageContents::buildModel() const
|
|||||||
targetFound = true;
|
targetFound = true;
|
||||||
} else {
|
} else {
|
||||||
foreach (const QString &file, files)
|
foreach (const QString &file, files)
|
||||||
m_deployables << MaemoDeployable(cleanPath(file), paths.first());
|
m_deployables << MaemoDeployable(
|
||||||
|
proFileWrapper->absFilePath(file), paths.first());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetFound) {
|
if (!targetFound) {
|
||||||
|
const Qt4ProFileNode * const proFileNode
|
||||||
|
= m_packageStep->qt4BuildConfiguration()->qt4Target()
|
||||||
|
->qt4Project()->rootProjectNode();
|
||||||
const QString remoteDir = proFileNode->projectType() == LibraryTemplate
|
const QString remoteDir = proFileNode->projectType() == LibraryTemplate
|
||||||
? QLatin1String("/usr/local/lib")
|
? QLatin1String("/usr/local/lib")
|
||||||
: QLatin1String("/usr/local/bin");
|
: QLatin1String("/usr/local/bin");
|
||||||
m_deployables.prepend(MaemoDeployable(m_packageStep->localExecutableFilePath(),
|
m_deployables.prepend(MaemoDeployable(m_packageStep->localExecutableFilePath(),
|
||||||
remoteDir));
|
remoteDir));
|
||||||
QString errorString;
|
|
||||||
if (!readProFileContents(&errorString)) {
|
if (!proFileWrapper->addVarValue(pathVar(TargetVar), remoteDir)
|
||||||
qWarning("Error reading .pro file: %s", qPrintable(errorString));
|
|| !proFileWrapper->addVarValue(InstallsVar, TargetVar)) {
|
||||||
return false;
|
qWarning("Error updating .pro file.");
|
||||||
}
|
|
||||||
addValueToProFile(pathVar(TargetVar), remoteDir);
|
|
||||||
addValueToProFile(InstallsVar, TargetVar);
|
|
||||||
if (!writeProFileContents(&errorString)) {
|
|
||||||
qWarning("Error writing .pro file: %s", qPrintable(errorString));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_initialized = true;
|
||||||
m_modified = true;
|
m_modified = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -153,21 +136,18 @@ MaemoDeployable MaemoPackageContents::deployableAt(int row) const
|
|||||||
bool MaemoPackageContents::addDeployable(const MaemoDeployable &deployable,
|
bool MaemoPackageContents::addDeployable(const MaemoDeployable &deployable,
|
||||||
QString *error)
|
QString *error)
|
||||||
{
|
{
|
||||||
if (m_deployables.contains(deployable) || deployableAt(0) == deployable)
|
if (m_deployables.contains(deployable)) {
|
||||||
|
*error = tr("File already in list.");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (!readProFileContents(error))
|
const QSharedPointer<ProFileWrapper> proFileWrapper
|
||||||
return false;
|
= m_packageStep->proFileWrapper();
|
||||||
|
|
||||||
QCryptographicHash elemHash(QCryptographicHash::Md5);
|
QCryptographicHash elemHash(QCryptographicHash::Md5);
|
||||||
elemHash.addData(deployable.localFilePath.toUtf8());
|
elemHash.addData(deployable.localFilePath.toUtf8());
|
||||||
const QString elemName = QString::fromAscii(elemHash.result().toHex());
|
const QString elemName = QString::fromAscii(elemHash.result().toHex());
|
||||||
addFileToProFile(filesVar(elemName), deployable.localFilePath);
|
proFileWrapper->addFile(filesVar(elemName), deployable.localFilePath);
|
||||||
addValueToProFile(pathVar(elemName), deployable.remoteDir);
|
proFileWrapper->addVarValue(pathVar(elemName), deployable.remoteDir);
|
||||||
addValueToProFile(InstallsVar, elemName);
|
proFileWrapper->addVarValue(InstallsVar, elemName);
|
||||||
|
|
||||||
if (!writeProFileContents(error))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||||
m_deployables << deployable;
|
m_deployables << deployable;
|
||||||
@@ -186,28 +166,24 @@ bool MaemoPackageContents::removeDeployableAt(int row, QString *error)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!readProFileContents(error))
|
const QString &filesVarName = filesVar(elemToRemove);
|
||||||
return false;
|
QSharedPointer<ProFileWrapper> proFileWrapper
|
||||||
|
= m_packageStep->proFileWrapper();
|
||||||
const QString filesVarName = filesVar(elemToRemove);
|
|
||||||
const bool isOnlyElem
|
const bool isOnlyElem
|
||||||
= m_proFileReader->values(filesVarName, m_proFile).count() == 1;
|
= proFileWrapper->varValues(filesVarName).count() == 1;
|
||||||
bool success
|
bool success
|
||||||
= removeFileFromProFile(filesVarName, deployable.localFilePath);
|
= proFileWrapper->removeFile(filesVarName, deployable.localFilePath);
|
||||||
if (success && isOnlyElem) {
|
if (success && isOnlyElem) {
|
||||||
success = removeValueFromProFile(pathVar(elemToRemove),
|
success = proFileWrapper->removeVarValue(pathVar(elemToRemove),
|
||||||
deployable.remoteDir);
|
deployable.remoteDir);
|
||||||
if (success)
|
if (success)
|
||||||
success = removeValueFromProFile(InstallsVar, elemToRemove);
|
success = proFileWrapper->removeVarValue(InstallsVar, elemToRemove);
|
||||||
}
|
}
|
||||||
if (!success) {
|
if (!success) {
|
||||||
*error = tr("Could not remove deployable from .pro file.");
|
*error = tr("Could not remove deployable from .pro file.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!writeProFileContents(error))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
m_deployables.removeAt(row - 1);
|
m_deployables.removeAt(row - 1);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
@@ -216,8 +192,7 @@ bool MaemoPackageContents::removeDeployableAt(int row, QString *error)
|
|||||||
|
|
||||||
int MaemoPackageContents::rowCount(const QModelIndex &parent) const
|
int MaemoPackageContents::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (!m_proFile)
|
buildModel();
|
||||||
buildModel();
|
|
||||||
return parent.isValid() ? 0 : m_deployables.count();
|
return parent.isValid() ? 0 : m_deployables.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,12 +229,6 @@ bool MaemoPackageContents::setData(const QModelIndex &index,
|
|||||||
|| role != Qt::EditRole)
|
|| role != Qt::EditRole)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QString error;
|
|
||||||
if (!readProFileContents(&error)) {
|
|
||||||
qWarning("%s", qPrintable(error));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MaemoDeployable &deployable = m_deployables[index.row()];
|
MaemoDeployable &deployable = m_deployables[index.row()];
|
||||||
const QString elemToChange = findInstallsElem(deployable);
|
const QString elemToChange = findInstallsElem(deployable);
|
||||||
if (elemToChange.isEmpty()) {
|
if (elemToChange.isEmpty()) {
|
||||||
@@ -267,16 +236,13 @@ bool MaemoPackageContents::setData(const QModelIndex &index,
|
|||||||
"INSTALLS element not found in .pro file");
|
"INSTALLS element not found in .pro file");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const QString pathElem = pathVar(elemToChange);
|
|
||||||
if (!removeValueFromProFile(pathElem, deployable.remoteDir)) {
|
|
||||||
qWarning("Error: Could not change remote path in .pro file.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const QString &newRemoteDir = value.toString();
|
|
||||||
addValueToProFile(pathElem, newRemoteDir);
|
|
||||||
|
|
||||||
if (!writeProFileContents(&error)) {
|
const QString &newRemoteDir = value.toString();
|
||||||
qWarning("%s", qPrintable(error));
|
QSharedPointer<ProFileWrapper> proFileWrapper
|
||||||
|
= m_packageStep->proFileWrapper();
|
||||||
|
if (!proFileWrapper->replaceVarValue(pathVar(elemToChange),
|
||||||
|
deployable.remoteDir, newRemoteDir)) {
|
||||||
|
qWarning("Error: Could not change remote path in .pro file.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,149 +261,29 @@ QVariant MaemoPackageContents::headerData(int section,
|
|||||||
|
|
||||||
QString MaemoPackageContents::remoteExecutableFilePath() const
|
QString MaemoPackageContents::remoteExecutableFilePath() const
|
||||||
{
|
{
|
||||||
if (!m_proFile)
|
return buildModel() ? deployableAt(0).remoteDir + '/'
|
||||||
buildModel();
|
+ m_packageStep->executableFileName() : QString();
|
||||||
return deployableAt(0).remoteDir + '/' + m_packageStep->executableFileName();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MaemoPackageContents::readProFileContents(QString *error) const
|
|
||||||
{
|
|
||||||
if (!m_proFileLines.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
QFile proFileOnDisk(m_proFileName);
|
|
||||||
if (!proFileOnDisk.open(QIODevice::ReadOnly)) {
|
|
||||||
*error = tr("Project file '%1' could not be opened for reading.")
|
|
||||||
.arg(m_proFileName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const QString proFileContents
|
|
||||||
= QString::fromLatin1(proFileOnDisk.readAll());
|
|
||||||
if (proFileOnDisk.error() != QFile::NoError) {
|
|
||||||
*error = tr("Project file '%1' could not be read.")
|
|
||||||
.arg(m_proFileName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_proFileLines = proFileContents.split('\n');
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MaemoPackageContents::writeProFileContents(QString *error) const
|
|
||||||
{
|
|
||||||
QFile proFileOnDisk(m_proFileName);
|
|
||||||
if (!proFileOnDisk.open(QIODevice::WriteOnly)) {
|
|
||||||
*error = tr("Project file '%1' could not be opened for writing.")
|
|
||||||
.arg(m_proFileName);
|
|
||||||
resetProFileContents();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Disconnect and reconnect FS watcher here.
|
|
||||||
proFileOnDisk.write(m_proFileLines.join("\n").toLatin1());
|
|
||||||
proFileOnDisk.close();
|
|
||||||
if (proFileOnDisk.error() != QFile::NoError) {
|
|
||||||
*error = tr("Project file '%1' could not be written.")
|
|
||||||
.arg(m_proFileName);
|
|
||||||
resetProFileContents();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_modified = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString MaemoPackageContents::cleanPath(const QString &relFileName) const
|
|
||||||
{
|
|
||||||
// I'd rather use QDir::cleanPath(), but that doesn't work well
|
|
||||||
// enough for redundant ".." dirs.
|
|
||||||
return QFileInfo(m_proFile->directoryName() + '/'
|
|
||||||
+ relFileName).canonicalFilePath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MaemoPackageContents::findInstallsElem(const MaemoDeployable &deployable) const
|
QString MaemoPackageContents::findInstallsElem(const MaemoDeployable &deployable) const
|
||||||
{
|
{
|
||||||
const QStringList elems = m_proFileReader->values(InstallsVar, m_proFile);
|
QSharedPointer<ProFileWrapper> proFileWrapper
|
||||||
|
= m_packageStep->proFileWrapper();
|
||||||
|
const QStringList &elems = proFileWrapper->varValues(InstallsVar);
|
||||||
foreach (const QString &elem, elems) {
|
foreach (const QString &elem, elems) {
|
||||||
const QStringList elemPaths
|
const QStringList elemPaths = proFileWrapper->varValues(pathVar(elem));
|
||||||
= m_proFileReader->values(pathVar(elem), m_proFile);
|
|
||||||
if (elemPaths.count() != 1 || elemPaths.first() != deployable.remoteDir)
|
if (elemPaths.count() != 1 || elemPaths.first() != deployable.remoteDir)
|
||||||
continue;
|
continue;
|
||||||
if (elem == TargetVar)
|
if (elem == TargetVar)
|
||||||
return elem;
|
return elem;
|
||||||
const QStringList elemFiles
|
const QStringList elemFiles = proFileWrapper->varValues(filesVar(elem));
|
||||||
= m_proFileReader->values(filesVar(elem), m_proFile);
|
|
||||||
foreach (const QString &file, elemFiles) {
|
foreach (const QString &file, elemFiles) {
|
||||||
if (cleanPath(file) == deployable.localFilePath)
|
if (proFileWrapper->absFilePath(file) == deployable.localFilePath)
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaemoPackageContents::addFileToProFile(const QString &var,
|
|
||||||
const QString &absFilePath)
|
|
||||||
{
|
|
||||||
ProWriter::addFiles(m_proFile, &m_proFileLines, m_proDir,
|
|
||||||
QStringList(absFilePath), var);
|
|
||||||
parseProFile(ParseFromLines);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaemoPackageContents::addValueToProFile(const QString &var,
|
|
||||||
const QString &value) const
|
|
||||||
{
|
|
||||||
ProWriter::addVarValues(m_proFile, &m_proFileLines, m_proDir,
|
|
||||||
QStringList(value), var);
|
|
||||||
parseProFile(ParseFromLines);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MaemoPackageContents::removeFileFromProFile(const QString &var,
|
|
||||||
const QString &absFilePath)
|
|
||||||
{
|
|
||||||
const bool success = ProWriter::removeFiles(m_proFile, &m_proFileLines,
|
|
||||||
m_proDir, QStringList(absFilePath),
|
|
||||||
QStringList(var)).isEmpty();
|
|
||||||
if (success)
|
|
||||||
parseProFile(ParseFromLines);
|
|
||||||
else
|
|
||||||
resetProFileContents();
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MaemoPackageContents::removeValueFromProFile(const QString &var,
|
|
||||||
const QString &value)
|
|
||||||
{
|
|
||||||
const bool success = ProWriter::removeVarValues(m_proFile,
|
|
||||||
&m_proFileLines, m_proDir, QStringList(value),
|
|
||||||
QStringList(var)).isEmpty();
|
|
||||||
if (success)
|
|
||||||
parseProFile(ParseFromLines);
|
|
||||||
else
|
|
||||||
resetProFileContents();
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaemoPackageContents::parseProFile(ParseType type) const
|
|
||||||
{
|
|
||||||
if (type == ParseFromLines) {
|
|
||||||
m_proFile = m_proFileReader->parsedProFile(m_proFileName, false,
|
|
||||||
m_proFileLines.join("\n"));
|
|
||||||
} else {
|
|
||||||
m_proFile = 0;
|
|
||||||
if (ProFile *pro = m_proFileReader->parsedProFile(m_proFileName)) {
|
|
||||||
if (m_proFileReader->accept(pro))
|
|
||||||
m_proFile = pro;
|
|
||||||
pro->deref();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaemoPackageContents::resetProFileContents() const
|
|
||||||
{
|
|
||||||
m_proFileLines.clear();
|
|
||||||
parseProFile(ParseFromFile);
|
|
||||||
if (!m_proFile)
|
|
||||||
qWarning("Fatal: Could not parse .pro file '%s'.",
|
|
||||||
qPrintable(m_proFileName));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Qt4ProjectManager
|
} // namespace Qt4ProjectManager
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -31,17 +31,9 @@
|
|||||||
#define MAEMOPACKAGECONTENTS_H
|
#define MAEMOPACKAGECONTENTS_H
|
||||||
|
|
||||||
#include <QtCore/QAbstractTableModel>
|
#include <QtCore/QAbstractTableModel>
|
||||||
#include <QtCore/QDir>
|
|
||||||
#include <QtCore/QHash>
|
#include <QtCore/QHash>
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
#include <QtCore/QScopedPointer>
|
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
#include <QtCore/QStringList>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class ProFile;
|
|
||||||
struct ProFileOption;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Qt4ProjectManager {
|
namespace Qt4ProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -75,8 +67,6 @@ public:
|
|||||||
MaemoPackageContents(MaemoPackageCreationStep *packageStep);
|
MaemoPackageContents(MaemoPackageCreationStep *packageStep);
|
||||||
~MaemoPackageContents();
|
~MaemoPackageContents();
|
||||||
|
|
||||||
bool init();
|
|
||||||
|
|
||||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
|
||||||
MaemoDeployable deployableAt(int row) const;
|
MaemoDeployable deployableAt(int row) const;
|
||||||
@@ -98,29 +88,13 @@ private:
|
|||||||
|
|
||||||
bool buildModel() const;
|
bool buildModel() const;
|
||||||
void resetProFileContents() const;
|
void resetProFileContents() const;
|
||||||
bool readProFileContents(QString *error) const;
|
|
||||||
bool writeProFileContents(QString *error) const;
|
|
||||||
|
|
||||||
QString cleanPath(const QString &relFileName) const;
|
|
||||||
|
|
||||||
QString findInstallsElem(const MaemoDeployable &deployable) const;
|
QString findInstallsElem(const MaemoDeployable &deployable) const;
|
||||||
void addFileToProFile(const QString &var, const QString &absFilePath);
|
|
||||||
void addValueToProFile(const QString &var, const QString &value) const;
|
|
||||||
bool removeFileFromProFile(const QString &var, const QString &absFilePath);
|
|
||||||
bool removeValueFromProFile(const QString &var, const QString &value);
|
|
||||||
|
|
||||||
enum ParseType { ParseFromFile, ParseFromLines };
|
|
||||||
void parseProFile(ParseType type) const;
|
|
||||||
|
|
||||||
const MaemoPackageCreationStep * const m_packageStep;
|
const MaemoPackageCreationStep * const m_packageStep;
|
||||||
QScopedPointer<ProFileOption> m_proFileOption;
|
|
||||||
QScopedPointer<ProFileReader> m_proFileReader;
|
|
||||||
mutable QList<MaemoDeployable> m_deployables;
|
mutable QList<MaemoDeployable> m_deployables;
|
||||||
mutable bool m_modified;
|
mutable bool m_modified;
|
||||||
mutable ProFile *m_proFile;
|
mutable bool m_initialized;
|
||||||
mutable QStringList m_proFileLines; // TODO: FS watcher
|
|
||||||
mutable QString m_proFileName;
|
|
||||||
mutable QDir m_proDir;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Qt4ProjectManager
|
} // namespace Qt4ProjectManager
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
#include "maemopackagecreationwidget.h"
|
#include "maemopackagecreationwidget.h"
|
||||||
#include "maemopackagecontents.h"
|
#include "maemopackagecontents.h"
|
||||||
#include "maemotoolchain.h"
|
#include "maemotoolchain.h"
|
||||||
|
#include "profilewrapper.h"
|
||||||
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
#include <qt4buildconfiguration.h>
|
#include <qt4buildconfiguration.h>
|
||||||
@@ -90,6 +91,8 @@ MaemoPackageCreationStep::MaemoPackageCreationStep(BuildConfiguration *buildConf
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MaemoPackageCreationStep::~MaemoPackageCreationStep() {}
|
||||||
|
|
||||||
bool MaemoPackageCreationStep::init()
|
bool MaemoPackageCreationStep::init()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -364,6 +367,18 @@ void MaemoPackageCreationStep::raiseError(const QString &shortMsg,
|
|||||||
TASK_CATEGORY_BUILDSYSTEM));
|
TASK_CATEGORY_BUILDSYSTEM));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSharedPointer<ProFileWrapper> MaemoPackageCreationStep::proFileWrapper() const
|
||||||
|
{
|
||||||
|
if (!m_proFileWrapper) {
|
||||||
|
const Qt4ProFileNode * const proFileNode = qt4BuildConfiguration()
|
||||||
|
->qt4Target()->qt4Project()->rootProjectNode();
|
||||||
|
m_proFileWrapper = QSharedPointer<ProFileWrapper>(
|
||||||
|
new ProFileWrapper(proFileNode->path()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_proFileWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
const QLatin1String MaemoPackageCreationStep::CreatePackageId("Qt4ProjectManager.MaemoPackageCreationStep");
|
const QLatin1String MaemoPackageCreationStep::CreatePackageId("Qt4ProjectManager.MaemoPackageCreationStep");
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -44,6 +44,8 @@
|
|||||||
|
|
||||||
#include <projectexplorer/buildstep.h>
|
#include <projectexplorer/buildstep.h>
|
||||||
|
|
||||||
|
#include <QtCore/QSharedPointer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QFile;
|
class QFile;
|
||||||
class QProcess;
|
class QProcess;
|
||||||
@@ -54,6 +56,7 @@ namespace Internal {
|
|||||||
|
|
||||||
class MaemoPackageContents;
|
class MaemoPackageContents;
|
||||||
class MaemoToolChain;
|
class MaemoToolChain;
|
||||||
|
class ProFileWrapper;
|
||||||
class Qt4BuildConfiguration;
|
class Qt4BuildConfiguration;
|
||||||
|
|
||||||
class MaemoPackageCreationStep : public ProjectExplorer::BuildStep
|
class MaemoPackageCreationStep : public ProjectExplorer::BuildStep
|
||||||
@@ -62,12 +65,14 @@ class MaemoPackageCreationStep : public ProjectExplorer::BuildStep
|
|||||||
friend class MaemoPackageCreationFactory;
|
friend class MaemoPackageCreationFactory;
|
||||||
public:
|
public:
|
||||||
MaemoPackageCreationStep(ProjectExplorer::BuildConfiguration *buildConfig);
|
MaemoPackageCreationStep(ProjectExplorer::BuildConfiguration *buildConfig);
|
||||||
|
~MaemoPackageCreationStep();
|
||||||
|
|
||||||
QString packageFilePath() const;
|
QString packageFilePath() const;
|
||||||
QString localExecutableFilePath() const;
|
QString localExecutableFilePath() const;
|
||||||
QString executableFileName() const;
|
QString executableFileName() const;
|
||||||
MaemoPackageContents *packageContents() const { return m_packageContents; }
|
MaemoPackageContents *packageContents() const { return m_packageContents; }
|
||||||
const Qt4BuildConfiguration *qt4BuildConfiguration() const;
|
const Qt4BuildConfiguration *qt4BuildConfiguration() const;
|
||||||
|
QSharedPointer<ProFileWrapper> proFileWrapper() const;
|
||||||
|
|
||||||
bool isPackagingEnabled() const { return m_packagingEnabled; }
|
bool isPackagingEnabled() const { return m_packagingEnabled; }
|
||||||
void setPackagingEnabled(bool enabled) { m_packagingEnabled = enabled; }
|
void setPackagingEnabled(bool enabled) { m_packagingEnabled = enabled; }
|
||||||
@@ -101,6 +106,7 @@ private:
|
|||||||
MaemoPackageContents *const m_packageContents;
|
MaemoPackageContents *const m_packageContents;
|
||||||
bool m_packagingEnabled;
|
bool m_packagingEnabled;
|
||||||
QString m_versionString;
|
QString m_versionString;
|
||||||
|
mutable QSharedPointer<ProFileWrapper> m_proFileWrapper;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
159
src/plugins/qt4projectmanager/qt-maemo/profilewrapper.cpp
Normal file
159
src/plugins/qt4projectmanager/qt-maemo/profilewrapper.cpp
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
#include "profilewrapper.h"
|
||||||
|
|
||||||
|
#include <prowriter.h>
|
||||||
|
#include <qt4projectmanager/profilereader.h>
|
||||||
|
|
||||||
|
#include <QtCore/QFile>
|
||||||
|
#include <QtCore/QFileInfo>
|
||||||
|
|
||||||
|
namespace Qt4ProjectManager {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
ProFileWrapper::ProFileWrapper(const QString &proFileName)
|
||||||
|
: m_proFileName(proFileName), m_proDir(QFileInfo(m_proFileName).dir()),
|
||||||
|
m_proFileOption(new ProFileOption)
|
||||||
|
{
|
||||||
|
parseProFile(ParseFromFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
ProFileWrapper::~ProFileWrapper() {}
|
||||||
|
|
||||||
|
QStringList ProFileWrapper::varValues(const QString &var) const
|
||||||
|
{
|
||||||
|
return m_proFileReader->values(var, m_proFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProFileWrapper::addVarValue(const QString &var, const QString &value)
|
||||||
|
{
|
||||||
|
if (!readProFileContents())
|
||||||
|
return false;
|
||||||
|
ProWriter::addVarValues(m_proFile, &m_proFileContents, m_proDir,
|
||||||
|
QStringList(value), var);
|
||||||
|
parseProFile(ParseFromLines);
|
||||||
|
return writeProFileContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProFileWrapper::addFile(const QString &var, const QString &absFilePath)
|
||||||
|
{
|
||||||
|
if (!readProFileContents())
|
||||||
|
return false;
|
||||||
|
ProWriter::addFiles(m_proFile, &m_proFileContents, m_proDir,
|
||||||
|
QStringList(absFilePath), var);
|
||||||
|
parseProFile(ParseFromLines);
|
||||||
|
return writeProFileContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProFileWrapper::removeVarValue(const QString &var, const QString &value)
|
||||||
|
{
|
||||||
|
if (!readProFileContents())
|
||||||
|
return false;
|
||||||
|
const bool success = ProWriter::removeVarValues(m_proFile,
|
||||||
|
&m_proFileContents, m_proDir, QStringList(value), QStringList(var))
|
||||||
|
.isEmpty();
|
||||||
|
if (success) {
|
||||||
|
parseProFile(ParseFromLines);
|
||||||
|
return writeProFileContents();
|
||||||
|
} else {
|
||||||
|
parseProFile(ParseFromFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProFileWrapper::removeFile(const QString &var, const QString &absFilePath)
|
||||||
|
{
|
||||||
|
if (!readProFileContents())
|
||||||
|
return false;
|
||||||
|
const bool success = ProWriter::removeFiles(m_proFile, &m_proFileContents,
|
||||||
|
m_proDir, QStringList(absFilePath), QStringList(var)).isEmpty();
|
||||||
|
if (success) {
|
||||||
|
parseProFile(ParseFromLines);
|
||||||
|
return writeProFileContents();
|
||||||
|
} else {
|
||||||
|
parseProFile(ParseFromFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProFileWrapper::replaceVarValue(const QString &var,
|
||||||
|
const QString &oldValue, const QString &newValue)
|
||||||
|
{
|
||||||
|
if (!readProFileContents())
|
||||||
|
return false;
|
||||||
|
const bool success = ProWriter::removeVarValues(m_proFile,
|
||||||
|
&m_proFileContents, m_proDir, QStringList(oldValue), QStringList(var))
|
||||||
|
.isEmpty();
|
||||||
|
if (!success) {
|
||||||
|
parseProFile(ParseFromFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ProWriter::addVarValues(m_proFile, &m_proFileContents, m_proDir,
|
||||||
|
QStringList(newValue), var);
|
||||||
|
parseProFile(ParseFromLines);
|
||||||
|
return writeProFileContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ProFileWrapper::absFilePath(const QString &relFilePath) const
|
||||||
|
{
|
||||||
|
// I'd rather use QDir::cleanPath(), but that doesn't work well
|
||||||
|
// enough for redundant ".." dirs.
|
||||||
|
return QFileInfo(m_proFile->directoryName() + '/' + relFilePath)
|
||||||
|
.canonicalFilePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProFileWrapper::parseProFile(ParseType type) const
|
||||||
|
{
|
||||||
|
m_proFileReader.reset(new ProFileReader(m_proFileOption.data()));
|
||||||
|
if (type == ParseFromLines) {
|
||||||
|
m_proFile = m_proFileReader->parsedProFile(m_proFileName, false,
|
||||||
|
m_proFileContents.join("\n"));
|
||||||
|
} else {
|
||||||
|
m_proFileContents.clear();
|
||||||
|
m_proFile = m_proFileReader->parsedProFile(m_proFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_proFile) {
|
||||||
|
qWarning("Fatal: Could not parse .pro file '%s'.",
|
||||||
|
qPrintable(m_proFileName));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_proFileReader->accept(m_proFile);
|
||||||
|
m_proFile->deref();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProFileWrapper::writeProFileContents()
|
||||||
|
{
|
||||||
|
QFile proFileOnDisk(m_proFileName);
|
||||||
|
if (!proFileOnDisk.open(QIODevice::WriteOnly)) {
|
||||||
|
parseProFile(ParseFromFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Disconnect and reconnect FS watcher here.
|
||||||
|
proFileOnDisk.write(m_proFileContents.join("\n").toLatin1());
|
||||||
|
proFileOnDisk.close();
|
||||||
|
if (proFileOnDisk.error() != QFile::NoError) {
|
||||||
|
parseProFile(ParseFromFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProFileWrapper::readProFileContents()
|
||||||
|
{
|
||||||
|
if (!m_proFileContents.isEmpty())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
QFile proFileOnDisk(m_proFileName);
|
||||||
|
if (!proFileOnDisk.open(QIODevice::ReadOnly))
|
||||||
|
return false;
|
||||||
|
const QString proFileContents
|
||||||
|
= QString::fromLatin1(proFileOnDisk.readAll());
|
||||||
|
if (proFileOnDisk.error() != QFile::NoError)
|
||||||
|
return false;
|
||||||
|
m_proFileContents = proFileContents.split('\n');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Qt4ProjectManager
|
||||||
51
src/plugins/qt4projectmanager/qt-maemo/profilewrapper.h
Normal file
51
src/plugins/qt4projectmanager/qt-maemo/profilewrapper.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#ifndef PROFILEWRAPPER_H
|
||||||
|
#define PROFILEWRAPPER_H
|
||||||
|
|
||||||
|
#include <QtCore/QDir>
|
||||||
|
#include <QtCore/QScopedPointer>
|
||||||
|
#include <QtCore/QString>
|
||||||
|
#include <QtCore/QString>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class ProFile;
|
||||||
|
struct ProFileOption;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Qt4ProjectManager {
|
||||||
|
namespace Internal {
|
||||||
|
class ProFileReader;
|
||||||
|
|
||||||
|
class ProFileWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ProFileWrapper(const QString &proFileName);
|
||||||
|
~ProFileWrapper();
|
||||||
|
|
||||||
|
// TODO: Higher-level versions of these specifically for INSTALLS vars
|
||||||
|
QStringList varValues(const QString &var) const;
|
||||||
|
bool addVarValue(const QString &var, const QString &value);
|
||||||
|
bool addFile(const QString &var, const QString &absFilePath);
|
||||||
|
bool removeVarValue(const QString &var, const QString &value);
|
||||||
|
bool removeFile(const QString &var, const QString &absFilePath);
|
||||||
|
bool replaceVarValue(const QString &var, const QString &oldValue,
|
||||||
|
const QString &newValue);
|
||||||
|
QString absFilePath(const QString &relFilePath) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum ParseType { ParseFromFile, ParseFromLines };
|
||||||
|
void parseProFile(ParseType type) const;
|
||||||
|
bool writeProFileContents();
|
||||||
|
bool readProFileContents();
|
||||||
|
|
||||||
|
const QString m_proFileName;
|
||||||
|
const QDir m_proDir;
|
||||||
|
mutable QStringList m_proFileContents;
|
||||||
|
QScopedPointer<ProFileOption> m_proFileOption;
|
||||||
|
mutable QScopedPointer<ProFileReader> m_proFileReader;
|
||||||
|
mutable ProFile *m_proFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Qt4ProjectManager
|
||||||
|
|
||||||
|
#endif // PROFILEWRAPPER_H
|
||||||
@@ -16,7 +16,8 @@ HEADERS += \
|
|||||||
$$PWD/maemopackagecreationfactory.h \
|
$$PWD/maemopackagecreationfactory.h \
|
||||||
$$PWD/maemopackagecreationwidget.h \
|
$$PWD/maemopackagecreationwidget.h \
|
||||||
$$PWD/maemopackagecontents.h \
|
$$PWD/maemopackagecontents.h \
|
||||||
$$PWD/qemuruntimemanager.h
|
$$PWD/qemuruntimemanager.h \
|
||||||
|
$$PWD/profilewrapper.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/maemoconfigtestdialog.cpp \
|
$$PWD/maemoconfigtestdialog.cpp \
|
||||||
@@ -35,7 +36,8 @@ SOURCES += \
|
|||||||
$$PWD/maemopackagecreationfactory.cpp \
|
$$PWD/maemopackagecreationfactory.cpp \
|
||||||
$$PWD/maemopackagecreationwidget.cpp \
|
$$PWD/maemopackagecreationwidget.cpp \
|
||||||
$$PWD/maemopackagecontents.cpp \
|
$$PWD/maemopackagecontents.cpp \
|
||||||
$$PWD/qemuruntimemanager.cpp
|
$$PWD/qemuruntimemanager.cpp \
|
||||||
|
$$PWD/profilewrapper.cpp
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
$$PWD/maemoconfigtestdialog.ui \
|
$$PWD/maemoconfigtestdialog.ui \
|
||||||
|
|||||||
Reference in New Issue
Block a user