2010-04-20 17:02:31 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "maemopackagecontents.h"
|
|
|
|
|
|
|
|
|
|
#include "maemopackagecreationstep.h"
|
2010-05-04 11:38:03 +02:00
|
|
|
#include "maemotoolchain.h"
|
2010-06-29 14:10:01 +02:00
|
|
|
#include "profilewrapper.h"
|
2010-05-04 11:38:03 +02:00
|
|
|
|
|
|
|
|
#include <qt4projectmanager/qt4buildconfiguration.h>
|
2010-05-05 09:12:25 +02:00
|
|
|
#include <qt4projectmanager/qt4project.h>
|
|
|
|
|
#include <qt4projectmanager/qt4target.h>
|
2010-05-04 11:38:03 +02:00
|
|
|
|
2010-06-16 08:57:13 +02:00
|
|
|
#include <QtCore/QCryptographicHash>
|
|
|
|
|
#include <QtCore/QFile>
|
2010-05-04 11:38:03 +02:00
|
|
|
#include <QtCore/QFileInfo>
|
2010-04-20 17:02:31 +02:00
|
|
|
|
2010-05-03 15:50:15 +02:00
|
|
|
namespace {
|
2010-06-16 08:57:13 +02:00
|
|
|
QString pathVar(const QString &var)
|
|
|
|
|
{
|
|
|
|
|
return var + QLatin1String(".path");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString filesVar(const QString &var)
|
|
|
|
|
{
|
|
|
|
|
return var + QLatin1String(".files");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QLatin1String InstallsVar("INSTALLS");
|
|
|
|
|
const QLatin1String TargetVar("target");
|
2010-05-03 15:50:15 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-20 17:02:31 +02:00
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
MaemoPackageContents::MaemoPackageContents(MaemoPackageCreationStep *packageStep)
|
|
|
|
|
: QAbstractTableModel(packageStep),
|
|
|
|
|
m_packageStep(packageStep),
|
2010-06-16 08:57:13 +02:00
|
|
|
m_modified(false),
|
2010-06-29 14:10:01 +02:00
|
|
|
m_initialized(false)
|
2010-06-16 08:57:13 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoPackageContents::~MaemoPackageContents() {}
|
|
|
|
|
|
|
|
|
|
bool MaemoPackageContents::buildModel() const
|
2010-04-20 17:02:31 +02:00
|
|
|
{
|
2010-06-29 14:10:01 +02:00
|
|
|
if (m_initialized)
|
|
|
|
|
return true;
|
2010-06-16 08:57:13 +02:00
|
|
|
|
2010-06-29 14:10:01 +02:00
|
|
|
m_deployables.clear();
|
|
|
|
|
QSharedPointer<ProFileWrapper> proFileWrapper
|
|
|
|
|
= m_packageStep->proFileWrapper();
|
|
|
|
|
const QStringList &elemList = proFileWrapper->varValues(InstallsVar);
|
2010-06-16 08:57:13 +02:00
|
|
|
bool targetFound = false;
|
|
|
|
|
foreach (const QString &elem, elemList) {
|
2010-06-29 14:10:01 +02:00
|
|
|
const QStringList &paths = proFileWrapper->varValues(pathVar(elem));
|
2010-06-16 08:57:13 +02:00
|
|
|
if (paths.count() != 1) {
|
|
|
|
|
qWarning("Error: Variable %s has %d values.",
|
|
|
|
|
qPrintable(pathVar(elem)), paths.count());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-29 14:10:01 +02:00
|
|
|
const QStringList &files = proFileWrapper->varValues(filesVar(elem));
|
2010-06-16 08:57:13 +02:00
|
|
|
if (files.isEmpty() && elem != TargetVar) {
|
|
|
|
|
qWarning("Error: Variable %s has no RHS.",
|
|
|
|
|
qPrintable(filesVar(elem)));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elem == TargetVar) {
|
2010-06-24 11:40:22 +02:00
|
|
|
m_deployables.prepend(MaemoDeployable(m_packageStep->localExecutableFilePath(),
|
2010-06-16 08:57:13 +02:00
|
|
|
paths.first()));
|
|
|
|
|
targetFound = true;
|
|
|
|
|
} else {
|
|
|
|
|
foreach (const QString &file, files)
|
2010-06-29 14:10:01 +02:00
|
|
|
m_deployables << MaemoDeployable(
|
|
|
|
|
proFileWrapper->absFilePath(file), paths.first());
|
2010-06-16 08:57:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!targetFound) {
|
2010-06-29 14:10:01 +02:00
|
|
|
const Qt4ProFileNode * const proFileNode
|
|
|
|
|
= m_packageStep->qt4BuildConfiguration()->qt4Target()
|
|
|
|
|
->qt4Project()->rootProjectNode();
|
2010-06-16 08:57:13 +02:00
|
|
|
const QString remoteDir = proFileNode->projectType() == LibraryTemplate
|
|
|
|
|
? QLatin1String("/usr/local/lib")
|
|
|
|
|
: QLatin1String("/usr/local/bin");
|
2010-06-24 11:40:22 +02:00
|
|
|
m_deployables.prepend(MaemoDeployable(m_packageStep->localExecutableFilePath(),
|
2010-06-16 08:57:13 +02:00
|
|
|
remoteDir));
|
2010-06-29 14:10:01 +02:00
|
|
|
|
|
|
|
|
if (!proFileWrapper->addVarValue(pathVar(TargetVar), remoteDir)
|
|
|
|
|
|| !proFileWrapper->addVarValue(InstallsVar, TargetVar)) {
|
|
|
|
|
qWarning("Error updating .pro file.");
|
2010-06-16 08:57:13 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-29 14:10:01 +02:00
|
|
|
m_initialized = true;
|
2010-06-16 08:57:13 +02:00
|
|
|
m_modified = true;
|
|
|
|
|
return true;
|
2010-04-20 17:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-22 14:40:08 +02:00
|
|
|
MaemoDeployable MaemoPackageContents::deployableAt(int row) const
|
2010-04-20 17:02:31 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(row >= 0 && row < rowCount());
|
2010-06-16 08:57:13 +02:00
|
|
|
return m_deployables.at(row);
|
2010-04-20 17:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-24 11:40:22 +02:00
|
|
|
bool MaemoPackageContents::addDeployable(const MaemoDeployable &deployable,
|
2010-06-16 08:57:13 +02:00
|
|
|
QString *error)
|
2010-05-03 14:47:40 +02:00
|
|
|
{
|
2010-06-29 14:10:01 +02:00
|
|
|
if (m_deployables.contains(deployable)) {
|
|
|
|
|
*error = tr("File already in list.");
|
2010-06-16 08:57:13 +02:00
|
|
|
return false;
|
2010-06-29 14:10:01 +02:00
|
|
|
}
|
|
|
|
|
const QSharedPointer<ProFileWrapper> proFileWrapper
|
|
|
|
|
= m_packageStep->proFileWrapper();
|
2010-06-16 08:57:13 +02:00
|
|
|
QCryptographicHash elemHash(QCryptographicHash::Md5);
|
|
|
|
|
elemHash.addData(deployable.localFilePath.toUtf8());
|
|
|
|
|
const QString elemName = QString::fromAscii(elemHash.result().toHex());
|
2010-06-29 14:10:01 +02:00
|
|
|
proFileWrapper->addFile(filesVar(elemName), deployable.localFilePath);
|
|
|
|
|
proFileWrapper->addVarValue(pathVar(elemName), deployable.remoteDir);
|
|
|
|
|
proFileWrapper->addVarValue(InstallsVar, elemName);
|
2010-06-16 08:57:13 +02:00
|
|
|
|
2010-05-03 14:47:40 +02:00
|
|
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
|
|
|
|
m_deployables << deployable;
|
|
|
|
|
endInsertRows();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-16 08:57:13 +02:00
|
|
|
bool MaemoPackageContents::removeDeployableAt(int row, QString *error)
|
2010-05-03 14:47:40 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(row > 0 && row < rowCount());
|
2010-06-16 08:57:13 +02:00
|
|
|
|
2010-06-24 11:40:22 +02:00
|
|
|
const MaemoDeployable &deployable = deployableAt(row);
|
2010-06-16 08:57:13 +02:00
|
|
|
const QString elemToRemove = findInstallsElem(deployable);
|
|
|
|
|
if (elemToRemove.isEmpty()) {
|
|
|
|
|
*error = tr("Inconsistent model: Deployable not found in .pro file.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-29 14:10:01 +02:00
|
|
|
const QString &filesVarName = filesVar(elemToRemove);
|
|
|
|
|
QSharedPointer<ProFileWrapper> proFileWrapper
|
|
|
|
|
= m_packageStep->proFileWrapper();
|
2010-06-16 08:57:13 +02:00
|
|
|
const bool isOnlyElem
|
2010-06-29 14:10:01 +02:00
|
|
|
= proFileWrapper->varValues(filesVarName).count() == 1;
|
2010-06-16 08:57:13 +02:00
|
|
|
bool success
|
2010-06-29 14:10:01 +02:00
|
|
|
= proFileWrapper->removeFile(filesVarName, deployable.localFilePath);
|
2010-06-16 08:57:13 +02:00
|
|
|
if (success && isOnlyElem) {
|
2010-06-29 14:10:01 +02:00
|
|
|
success = proFileWrapper->removeVarValue(pathVar(elemToRemove),
|
2010-06-16 08:57:13 +02:00
|
|
|
deployable.remoteDir);
|
|
|
|
|
if (success)
|
2010-06-29 14:10:01 +02:00
|
|
|
success = proFileWrapper->removeVarValue(InstallsVar, elemToRemove);
|
2010-06-16 08:57:13 +02:00
|
|
|
}
|
|
|
|
|
if (!success) {
|
|
|
|
|
*error = tr("Could not remove deployable from .pro file.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-03 14:47:40 +02:00
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
2010-05-04 11:38:03 +02:00
|
|
|
m_deployables.removeAt(row - 1);
|
2010-05-03 14:47:40 +02:00
|
|
|
endRemoveRows();
|
2010-06-16 08:57:13 +02:00
|
|
|
return true;
|
2010-05-03 14:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-20 17:02:31 +02:00
|
|
|
int MaemoPackageContents::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
2010-06-29 14:10:01 +02:00
|
|
|
buildModel();
|
2010-06-16 08:57:13 +02:00
|
|
|
return parent.isValid() ? 0 : m_deployables.count();
|
2010-04-20 17:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int MaemoPackageContents::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
return parent.isValid() ? 0 : 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant MaemoPackageContents::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
2010-05-04 11:38:03 +02:00
|
|
|
if (!index.isValid() || index.row() >= rowCount())
|
2010-04-20 17:02:31 +02:00
|
|
|
return QVariant();
|
|
|
|
|
|
2010-06-22 14:40:08 +02:00
|
|
|
const MaemoDeployable &d = deployableAt(index.row());
|
2010-05-04 11:38:03 +02:00
|
|
|
if (index.column() == 0 && role == Qt::DisplayRole)
|
|
|
|
|
return d.localFilePath;
|
|
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
2010-06-07 17:13:11 +02:00
|
|
|
return d.remoteDir;
|
2010-05-04 11:38:03 +02:00
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags MaemoPackageContents::flags(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
Qt::ItemFlags parentFlags = QAbstractTableModel::flags(index);
|
|
|
|
|
if (index.column() == 1)
|
|
|
|
|
return parentFlags | Qt::ItemIsEditable;
|
|
|
|
|
return parentFlags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoPackageContents::setData(const QModelIndex &index,
|
|
|
|
|
const QVariant &value, int role)
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid() || index.row() >= rowCount() || index.column() != 1
|
|
|
|
|
|| role != Qt::EditRole)
|
|
|
|
|
return false;
|
|
|
|
|
|
2010-06-24 11:40:22 +02:00
|
|
|
MaemoDeployable &deployable = m_deployables[index.row()];
|
2010-06-16 08:57:13 +02:00
|
|
|
const QString elemToChange = findInstallsElem(deployable);
|
|
|
|
|
if (elemToChange.isEmpty()) {
|
|
|
|
|
qWarning("Error: Inconsistent model. "
|
|
|
|
|
"INSTALLS element not found in .pro file");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-29 14:10:01 +02:00
|
|
|
const QString &newRemoteDir = value.toString();
|
|
|
|
|
QSharedPointer<ProFileWrapper> proFileWrapper
|
|
|
|
|
= m_packageStep->proFileWrapper();
|
|
|
|
|
if (!proFileWrapper->replaceVarValue(pathVar(elemToChange),
|
|
|
|
|
deployable.remoteDir, newRemoteDir)) {
|
|
|
|
|
qWarning("Error: Could not change remote path in .pro file.");
|
2010-06-16 08:57:13 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deployable.remoteDir = newRemoteDir;
|
2010-05-04 11:38:03 +02:00
|
|
|
emit dataChanged(index, index);
|
|
|
|
|
return true;
|
2010-04-20 17:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-26 14:10:26 +02:00
|
|
|
QVariant MaemoPackageContents::headerData(int section,
|
|
|
|
|
Qt::Orientation orientation, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (orientation == Qt::Vertical || role != Qt::DisplayRole)
|
|
|
|
|
return QVariant();
|
2010-06-07 17:13:11 +02:00
|
|
|
return section == 0 ? tr("Local File Path") : tr("Remote Directory");
|
2010-04-26 14:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-16 08:57:13 +02:00
|
|
|
QString MaemoPackageContents::remoteExecutableFilePath() const
|
|
|
|
|
{
|
2010-06-29 14:10:01 +02:00
|
|
|
return buildModel() ? deployableAt(0).remoteDir + '/'
|
|
|
|
|
+ m_packageStep->executableFileName() : QString();
|
2010-06-16 08:57:13 +02:00
|
|
|
}
|
2010-05-31 12:28:02 +02:00
|
|
|
|
2010-06-24 11:40:22 +02:00
|
|
|
QString MaemoPackageContents::findInstallsElem(const MaemoDeployable &deployable) const
|
2010-06-16 08:57:13 +02:00
|
|
|
{
|
2010-06-29 14:10:01 +02:00
|
|
|
QSharedPointer<ProFileWrapper> proFileWrapper
|
|
|
|
|
= m_packageStep->proFileWrapper();
|
|
|
|
|
const QStringList &elems = proFileWrapper->varValues(InstallsVar);
|
2010-06-16 08:57:13 +02:00
|
|
|
foreach (const QString &elem, elems) {
|
2010-06-29 14:10:01 +02:00
|
|
|
const QStringList elemPaths = proFileWrapper->varValues(pathVar(elem));
|
2010-06-16 08:57:13 +02:00
|
|
|
if (elemPaths.count() != 1 || elemPaths.first() != deployable.remoteDir)
|
|
|
|
|
continue;
|
|
|
|
|
if (elem == TargetVar)
|
|
|
|
|
return elem;
|
2010-06-29 14:10:01 +02:00
|
|
|
const QStringList elemFiles = proFileWrapper->varValues(filesVar(elem));
|
2010-06-16 08:57:13 +02:00
|
|
|
foreach (const QString &file, elemFiles) {
|
2010-06-29 14:10:01 +02:00
|
|
|
if (proFileWrapper->absFilePath(file) == deployable.localFilePath)
|
2010-06-16 08:57:13 +02:00
|
|
|
return elem;
|
|
|
|
|
}
|
2010-05-31 12:28:02 +02:00
|
|
|
}
|
2010-06-16 08:57:13 +02:00
|
|
|
return QString();
|
2010-05-03 15:50:15 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-20 17:02:31 +02:00
|
|
|
} // namespace Qt4ProjectManager
|
|
|
|
|
} // namespace Internal
|